Skip to content

Commit 70822f9

Browse files
Jeasminejkasten2
authored andcommitted
Add Receive Receipt call
* Send receice receipt call whenever a notification arrives to the cellphone
1 parent b482e92 commit 70822f9

15 files changed

+316
-61
lines changed

iOS_SDK/OneSignalDevApp/OneSignalDevApp/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
<string>Test Location</string>
3030
<key>NSLocationWhenInUseUsageDescription</key>
3131
<string>Test Location2</string>
32+
<key>OneSignal_disable_badge_clearing</key>
33+
<false/>
3234
<key>OneSignal_require_privacy_consent</key>
3335
<false/>
3436
<key>UIBackgroundModes</key>
@@ -43,8 +45,6 @@
4345
<array>
4446
<string>armv7</string>
4547
</array>
46-
<key>OneSignal_disable_badge_clearing</key>
47-
<false/>
4848
<key>UISupportedInterfaceOrientations</key>
4949
<array>
5050
<string>UIInterfaceOrientationPortrait</string>
16 KB
Binary file not shown.

iOS_SDK/OneSignalSDK/OneSignal.xcodeproj/project.pbxproj

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
4529DEED1FA83C5D00CEAB1D /* OneSignalHelperOverrider.m in Sources */ = {isa = PBXBuildFile; fileRef = 4529DEEC1FA83C5D00CEAB1D /* OneSignalHelperOverrider.m */; };
5959
4529DEF01FA8433500CEAB1D /* NSLocaleOverrider.m in Sources */ = {isa = PBXBuildFile; fileRef = 4529DEEF1FA8433500CEAB1D /* NSLocaleOverrider.m */; };
6060
4529DEF31FA8440A00CEAB1D /* UIAlertViewOverrider.m in Sources */ = {isa = PBXBuildFile; fileRef = 4529DEF21FA8440A00CEAB1D /* UIAlertViewOverrider.m */; };
61-
4529DEF61FA8460C00CEAB1D /* UnitTestAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4529DEF51FA8460C00CEAB1D /* UnitTestAppDelegate.m */; };
6261
4529DF0C1FA932AC00CEAB1D /* OneSignalTrackFirebaseAnalytics.m in Sources */ = {isa = PBXBuildFile; fileRef = 4529DF0B1FA932AC00CEAB1D /* OneSignalTrackFirebaseAnalytics.m */; };
6362
454F94F21FAD218000D74CCF /* OneSignalNotificationServiceExtensionHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 454F94F11FAD218000D74CCF /* OneSignalNotificationServiceExtensionHandler.m */; };
6463
454F94F51FAD2E5A00D74CCF /* OSNotificationPayload.m in Sources */ = {isa = PBXBuildFile; fileRef = 454F94F41FAD2E5A00D74CCF /* OSNotificationPayload.m */; };
@@ -107,6 +106,10 @@
107106
7AFE856D2368DDB80091D6A5 /* OSFocusCallParams.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFE856A2368DDB80091D6A5 /* OSFocusCallParams.m */; };
108107
7AFE856F2368DDC50091D6A5 /* OSFocusCallParams.h in Headers */ = {isa = PBXBuildFile; fileRef = 7AFE856E2368DDC50091D6A5 /* OSFocusCallParams.h */; };
109108
5B58E4F8237CE7B4009401E0 /* UIDeviceOverrider.m in Sources */ = {isa = PBXBuildFile; fileRef = 5B58E4F6237CE7B4009401E0 /* UIDeviceOverrider.m */; };
109+
7A9173A2231971E5007848FA /* OSReceiveReceiptController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7A9173A1231971E5007848FA /* OSReceiveReceiptController.m */; };
110+
7ADF891C230DB5BD0054E0D6 /* UnitTestAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4529DEF51FA8460C00CEAB1D /* UnitTestAppDelegate.m */; };
111+
7ADF891E230DB8290054E0D6 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7ADF891D230DB8290054E0D6 /* CoreGraphics.framework */; };
112+
7AF8FDBA2329656E00A19245 /* OneSignalUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AF8FDB92329656E00A19245 /* OneSignalUserDefaults.m */; };
110113
911E2CBD1E398AB3003112A4 /* UnitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 911E2CBC1E398AB3003112A4 /* UnitTests.m */; };
111114
911E2CC51E398B53003112A4 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3E08E2701D49A5C8002176DE /* SystemConfiguration.framework */; };
112115
911E2CC61E398B97003112A4 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 37E6B2BA19D9CAF300D0C601 /* UIKit.framework */; };
@@ -409,6 +412,11 @@
409412
7AFE856E2368DDC50091D6A5 /* OSFocusCallParams.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSFocusCallParams.h; sourceTree = "<group>"; };
410413
5B58E4F3237CE7B3009401E0 /* UIDeviceOverrider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIDeviceOverrider.h; sourceTree = "<group>"; };
411414
5B58E4F6237CE7B4009401E0 /* UIDeviceOverrider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIDeviceOverrider.m; sourceTree = "<group>"; };
415+
7A9173A1231971E5007848FA /* OSReceiveReceiptController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OSReceiveReceiptController.m; sourceTree = "<group>"; };
416+
7A9173A3231971F8007848FA /* OSReceiveReceiptController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSReceiveReceiptController.h; sourceTree = "<group>"; };
417+
7ADF891D230DB8290054E0D6 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
418+
7AF8FDB82329655C00A19245 /* OneSignalUserDefaults.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OneSignalUserDefaults.h; sourceTree = "<group>"; };
419+
7AF8FDB92329656E00A19245 /* OneSignalUserDefaults.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OneSignalUserDefaults.m; sourceTree = "<group>"; };
412420
911E2CBA1E398AB3003112A4 /* UnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
413421
911E2CBC1E398AB3003112A4 /* UnitTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UnitTests.m; sourceTree = "<group>"; };
414422
911E2CBE1E398AB3003112A4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -712,6 +720,13 @@
712720
9D1BD95B2376622700A064F7 /* Model */,
713721
);
714722
name = OutcomeEvents;
723+
7A9173A023197198007848FA /* ReceiveReceipt */ = {
724+
isa = PBXGroup;
725+
children = (
726+
7A9173A1231971E5007848FA /* OSReceiveReceiptController.m */,
727+
7A9173A3231971F8007848FA /* OSReceiveReceiptController.h */,
728+
);
729+
name = ReceiveReceipt;
715730
sourceTree = "<group>";
716731
};
717732
911E2CBB1E398AB3003112A4 /* UnitTests */ = {
@@ -752,6 +767,7 @@
752767
children = (
753768
7A674F172360D7DB001F9ACD /* OnFocus */,
754769
7ADE379222E8B56F00263048 /* OutcomeEvents */,
770+
7A9173A023197198007848FA /* ReceiveReceipt */,
755771
454F94F31FAD263300D74CCF /* Model */,
756772
9129C6B41E89E541009CB6A0 /* State */,
757773
91F58D7B1E7C7EE30017D24D /* NotificationSettings */,
@@ -794,6 +810,8 @@
794810
CAABF34A205B15780042F8E5 /* OneSignalExtensionBadgeHandler.m */,
795811
CAAEA68621ED68A40049CF15 /* OneSignalNotificationCategoryController.h */,
796812
CAAEA68521ED68A30049CF15 /* OneSignalNotificationCategoryController.m */,
813+
7AF8FDB82329655C00A19245 /* OneSignalUserDefaults.h */,
814+
7AF8FDB92329656E00A19245 /* OneSignalUserDefaults.m */,
797815
);
798816
path = Source;
799817
sourceTree = "<group>";
@@ -1093,7 +1111,7 @@
10931111
};
10941112
911E2CB91E398AB3003112A4 = {
10951113
CreatedOnToolsVersion = 8.1;
1096-
DevelopmentTeam = 99SW8E36CT;
1114+
DevelopmentTeam = UKWHJ5PHKD;
10971115
ProvisioningStyle = Automatic;
10981116
};
10991117
CA2951BD2167F9860064227A = {
@@ -1181,6 +1199,7 @@
11811199
buildActionMask = 2147483647;
11821200
files = (
11831201
9D1BD968237A28FC00A064F7 /* OSUniqueOutcomeNotification.m in Sources */,
1202+
7A9173A2231971E5007848FA /* OSReceiveReceiptController.m in Sources */,
11841203
9124120E1E73342200E41FD7 /* OneSignal.m in Sources */,
11851204
CACBAA97218A6243000ACAA5 /* OSMessagingController.m in Sources */,
11861205
CA36F35921C33A2500300C77 /* OSInAppMessageController.m in Sources */,
@@ -1235,6 +1254,7 @@
12351254
9129C6BE1E89E7AB009CB6A0 /* OSSubscription.m in Sources */,
12361255
7AECE59023674A9700537907 /* OSAttributedFocusTimeProcessor.m in Sources */,
12371256
7ADE379422E8B69C00263048 /* OneSignalOutcomeEventsController.m in Sources */,
1257+
7AF8FDBA2329656E00A19245 /* OneSignalUserDefaults.m in Sources */,
12381258
912412361E73342200E41FD7 /* OneSignalTrackIAP.m in Sources */,
12391259
CAABF34B205B15780042F8E5 /* OneSignalExtensionBadgeHandler.m in Sources */,
12401260
CACBAA9D218A6243000ACAA5 /* OSInAppMessageView.m in Sources */,
@@ -1404,6 +1424,7 @@
14041424
4529DEE11FA82AB300CEAB1D /* NSBundleOverrider.m in Sources */,
14051425
912412441E73342200E41FD7 /* UNUserNotificationCenter+OneSignal.m in Sources */,
14061426
03866CC12378A67B0009C1D8 /* RestClientAsserts.m in Sources */,
1427+
7ADF891C230DB5BD0054E0D6 /* UnitTestAppDelegate.m in Sources */,
14071428
9124123C1E73342200E41FD7 /* OneSignalWebView.m in Sources */,
14081429
CAB411AE208931EE005A70D1 /* DummyNotificationCenterDelegate.m in Sources */,
14091430
4529DEF01FA8433500CEAB1D /* NSLocaleOverrider.m in Sources */,

iOS_SDK/OneSignalSDK/Source/OSNotificationPayload.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,8 @@ -(void)parseOtherApnsFields {
186186
_category = aps[@"category"];
187187
}
188188

189+
- (NSString *)description {
190+
return [NSString stringWithFormat: @"Photo: notificationID=%@ templateID=%@ templateName=%@ contentAvailable=%@ mutableContent=%@ category=%@ rawPayload=%@", _notificationID, _templateID, _templateName, _contentAvailable ? @"YES" : @"NO", _mutableContent ? @"YES" : @"NO", _category, _rawPayload];
191+
}
192+
189193
@end
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2017 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#import "OneSignal.h"
29+
30+
@interface OSReceiveReceiptController : NSObject
31+
32+
- (void)sendReceiveReceiptCachedWithNotification:(NSString *)notificationId;
33+
34+
- (void)sendReceiveReceiptWithPlayerId:(nonnull NSString *)playerId
35+
notificationId:(nonnull NSString *)notificationId
36+
appId:(nonnull NSString *)appId;
37+
38+
- (void)sendReceiveReceiptWithPlayerId:(nonnull NSString *)playerId
39+
notificationId:(nonnull NSString *)notificationId
40+
appId:(nonnull NSString *)appId
41+
successBlock:(nullable OSResultSuccessBlock)success
42+
failureBlock:(nullable OSFailureBlock)failure;
43+
44+
@end
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* Modified MIT License
3+
*
4+
* Copyright 2017 OneSignal
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* 1. The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* 2. All copies of substantial portions of the Software may only be used in connection
17+
* with services provided by OneSignal.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
*/
27+
28+
#import <Foundation/Foundation.h>
29+
#import "OSReceiveReceiptController.h"
30+
#import "Requests.h"
31+
#import "OneSignalClient.h"
32+
#import "OSSubscription.h"
33+
#import "OneSignalCommonDefines.h"
34+
#import "OneSignalUserDefaults.h"
35+
36+
@implementation OSReceiveReceiptController
37+
38+
- (instancetype)init
39+
{
40+
self = [super init];
41+
return self;
42+
}
43+
44+
- (void)sendReceiveReceiptCachedWithNotification:(NSString *)notificationId {
45+
NSUserDefaults *userDefaultsShared = [OneSignalSharedUserDefaults getSharedUserDefault];
46+
let currentSubscriptionState = [[OSSubscriptionState alloc] initAsFrom];
47+
let playerId = [currentSubscriptionState userId];
48+
let appId = [userDefaultsShared stringForKey:APP_ID];
49+
50+
[self sendReceiveReceiptWithPlayerId:playerId notificationId:notificationId appId:appId];
51+
}
52+
53+
- (void)sendReceiveReceiptWithPlayerId:(NSString *)playerId notificationId:(NSString *)notificationId appId:(NSString *)appId {
54+
[self sendReceiveReceiptWithPlayerId:playerId notificationId:notificationId appId:appId successBlock:nil failureBlock:nil];
55+
}
56+
57+
- (void)sendReceiveReceiptWithPlayerId:(nonnull NSString *)playerId
58+
notificationId:(nonnull NSString *)notificationId
59+
appId:(nonnull NSString *)appId
60+
successBlock:(nullable OSResultSuccessBlock)success
61+
failureBlock:(nullable OSFailureBlock)failure {
62+
let message = [NSString stringWithFormat:@"OneSignal sendReceiveReceiptWithPlayerId playerId:%@ notificationId: %@, appId: %@", playerId, notificationId, appId];
63+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:message];
64+
65+
if (![self checkReceiveReceiptsStatus]) {
66+
[OneSignal onesignal_Log:ONE_S_LL_VERBOSE message:@"sendReceiveReceiptWithPlayerId disabled"];
67+
return;
68+
}
69+
OSRequestReceiveReceipts *request = [OSRequestReceiveReceipts withPlayerId:playerId notificationId:notificationId appId:appId];
70+
71+
[OneSignalClient.sharedClient executeRequest:request onSuccess:^(NSDictionary *result) {
72+
if (success) {
73+
success(result);
74+
}
75+
} onFailure:^(NSError *error) {
76+
if (failure) {
77+
failure(error);
78+
}
79+
}];
80+
}
81+
82+
- (BOOL)checkReceiveReceiptsStatus {
83+
return [OneSignalSharedUserDefaults getSavedBool:ONESIGNAL_ENABLE_RECEIVE_RECEIPTS defaultValue:NO];
84+
}
85+
86+
@end

iOS_SDK/OneSignalSDK/Source/OSSubscription.m

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#import "OSSubscription.h"
2929
#import "OneSignalCommonDefines.h"
30-
30+
#import "OneSignalUserDefaults.h"
3131

3232
#pragma clang diagnostic push
3333
#pragma clang diagnostic ignored "-Wundeclared-selector"
@@ -44,9 +44,9 @@ - (instancetype)initAsToWithPermision:(BOOL)permission {
4444
_accpeted = permission;
4545

4646
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
47-
_userId = [userDefaults stringForKey:USERID];
4847
_pushToken = [userDefaults stringForKey:DEVICE_TOKEN];
4948
_userSubscriptionSetting = [userDefaults objectForKey:SUBSCRIPTION] == nil;
49+
_userId = [OneSignalSharedUserDefaults getSavedString:USERID_LAST defaultValue:nil];
5050

5151
return self;
5252
}
@@ -59,12 +59,12 @@ - (BOOL)compare:(OSSubscriptionState*)from {
5959
}
6060

6161
- (instancetype)initAsFrom {
62-
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
62+
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
6363

64-
_userId = [userDefaults stringForKey:USERID_LAST];
6564
_pushToken = [userDefaults stringForKey:PUSH_TOKEN];
6665
_userSubscriptionSetting = [userDefaults objectForKey:SUBSCRIPTION_SETTING] == nil;
6766
_accpeted = [userDefaults boolForKey:ACCEPTED_PERMISSION];
67+
_userId = [OneSignalSharedUserDefaults getSavedString:USERID_LAST defaultValue:nil];
6868

6969
return self;
7070
}
@@ -77,10 +77,11 @@ - (void)persistAsFrom {
7777
strUserSubscriptionSetting = @"no";
7878

7979
[userDefaults setObject:strUserSubscriptionSetting forKey:SUBSCRIPTION_SETTING];
80-
[userDefaults setObject:_userId forKey:USERID_LAST];
8180
[userDefaults setObject:_pushToken forKey:PUSH_TOKEN];
8281
[userDefaults setBool:_accpeted forKey:ACCEPTED_PERMISSION];
8382

83+
[OneSignalSharedUserDefaults saveString:_userId withKey:USERID_LAST];
84+
8485
[userDefaults synchronize];
8586
}
8687

@@ -97,7 +98,6 @@ - (instancetype)copyWithZone:(NSZone*)zone {
9798
return copy;
9899
}
99100

100-
101101
- (void)onChanged:(OSPermissionState*)state {
102102
[self setAccepted:state.accepted];
103103
}

0 commit comments

Comments
 (0)