Skip to content

Commit d84070d

Browse files
committed
[example app] observers, update bundle ID
* Add push subscription observer and permission observer * Missed this requirement for testing -> update bundle ID to staging, needs to be `com.onesignal.example.staging` * Move set log level up to capture logs earlier. * Not making any structural changes to example app, but link some buttons to new methods like login, logout
1 parent 8689a9e commit d84070d

File tree

9 files changed

+32
-26
lines changed

9 files changed

+32
-26
lines changed

iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
#import <UIKit/UIKit.h>
3232
#import <OneSignalFramework/OneSignalFramework.h>
3333

34-
// TODO: Add subscription observer
35-
@interface AppDelegate : UIResponder <UIApplicationDelegate, OSPermissionObserver, OSInAppMessageLifecycleHandler>
34+
@interface AppDelegate : UIResponder <UIApplicationDelegate, OSPermissionObserver, OSInAppMessageLifecycleHandler, OSPushSubscriptionObserver>
3635

3736
@property (strong, nonatomic) UIWindow *window;
3837

iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
5050
// [FIRApp configure];
5151

5252
NSLog(@"Bundle URL: %@", [[NSBundle mainBundle] bundleURL]);
53+
[OneSignal.Debug setLogLevel:ONE_S_LL_VERBOSE];
54+
[OneSignal.Debug setVisualLevel:ONE_S_LL_NONE];
5355

5456
[OneSignal initialize:[AppDelegate getOneSignalAppId] withLaunchOptions:launchOptions];
5557

56-
[OneSignal.Debug setLogLevel:ONE_S_LL_VERBOSE];
57-
[OneSignal.Debug setVisualLevel:ONE_S_LL_NONE];
5858
_notificationDelegate = [OneSignalNotificationCenterDelegate new];
5959

6060
id openNotificationHandler = ^(OSNotificationOpenedResult *result) {
@@ -94,6 +94,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
9494
[OneSignal.Notifications setNotificationWillShowInForegroundHandler:notificationReceiverBlock];
9595
[OneSignal.Notifications setNotificationOpenedHandler:openNotificationHandler];
9696

97+
OSPushSubscriptionState* state = [OneSignal.User.pushSubscription addObserver:self];
98+
NSLog(@"OneSignal Demo App push subscription observer added, current state: %@", state);
99+
100+
[OneSignal.Notifications addPermissionObserver:self];
101+
97102
NSLog(@"UNUserNotificationCenter.delegate: %@", UNUserNotificationCenter.currentNotificationCenter.delegate);
98103

99104
return YES;
@@ -120,12 +125,11 @@ - (void) onOSPermissionChanged:(OSPermissionStateChanges*)stateChanges {
120125
NSLog(@"onOSPermissionChanged: %@", stateChanges);
121126
}
122127

123-
// TODO: Add push sub observer
124-
//- (void) onOSSubscriptionChanged:(OSSubscriptionStateChanges*)stateChanges {
125-
// NSLog(@"onOSSubscriptionChanged: %@", stateChanges);
126-
// ViewController* mainController = (ViewController*) self.window.rootViewController;
127-
// mainController.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) stateChanges.to.isSubscribed;
128-
//}
128+
- (void)onOSPushSubscriptionChangedWithStateChanges:(OSPushSubscriptionStateChanges *)stateChanges {
129+
NSLog(@"onOSPushSubscriptionChangedWithStateChanges: %@", stateChanges);
130+
ViewController* mainController = (ViewController*) self.window.rootViewController;
131+
mainController.subscriptionSegmentedControl.selectedSegmentIndex = (NSInteger) stateChanges.to.optedIn;
132+
}
129133

130134
#pragma mark OSInAppMessageDelegate
131135

iOS_SDK/OneSignalDevApp/OneSignalDevApp/Base.lproj/Main.storyboard

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<constraint firstAttribute="width" constant="68" id="com-ja-CVD"/>
4444
</constraints>
4545
<color key="tintColor" red="1" green="0.1367101157" blue="0.01701983743" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
46-
<state key="normal" title="Get Tags"/>
46+
<state key="normal" title="INFO"/>
4747
<connections>
4848
<action selector="getTagsButton:" destination="BYZ-38-t0r" eventType="touchUpInside" id="Pp8-oA-Zrh"/>
4949
</connections>
@@ -298,7 +298,7 @@
298298
<rect key="frame" x="118" y="581" width="136" height="30"/>
299299
<fontDescription key="fontDescription" name=".AppleSystemUIFont" family=".AppleSystemUIFont" pointSize="15"/>
300300
<color key="tintColor" red="1" green="0.1367101157" blue="0.01701983743" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
301-
<state key="normal" title="Set External User Id"/>
301+
<state key="normal" title="Login to External User Id"/>
302302
<connections>
303303
<action selector="setExternalUserId:" destination="BYZ-38-t0r" eventType="touchUpInside" id="DXf-1K-Lkc"/>
304304
</connections>
@@ -374,11 +374,11 @@
374374
<fontDescription key="fontDescription" type="system" pointSize="14"/>
375375
<textInputTraits key="textInputTraits"/>
376376
</textField>
377-
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" selected="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="OiG-L7-Ot2" userLabel="Remove External User Id">
377+
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" selected="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="OiG-L7-Ot2" userLabel="Logout">
378378
<rect key="frame" x="103" y="619" width="168" height="30"/>
379379
<fontDescription key="fontDescription" name=".AppleSystemUIFont" family=".AppleSystemUIFont" pointSize="15"/>
380380
<color key="tintColor" red="1" green="0.1367101157" blue="0.01701983743" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
381-
<state key="normal" title="Remove External User Id"/>
381+
<state key="normal" title="Logout"/>
382382
<connections>
383383
<action selector="removeExternalUserId:" destination="BYZ-38-t0r" eventType="touchUpInside" id="F3N-HQ-tSv"/>
384384
</connections>

iOS_SDK/OneSignalDevApp/OneSignalDevApp/OneSignalDevApp.entitlements

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</array>
1212
<key>com.apple.security.application-groups</key>
1313
<array>
14-
<string>group.com.onesignal.example.onesignal</string>
14+
<string>group.com.onesignal.example.staging.onesignal</string>
1515
</array>
1616
</dict>
1717
</plist>

iOS_SDK/OneSignalDevApp/OneSignalDevApp/ViewController.m

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,14 @@ - (void)handleMessageAction:(NSString *)actionId {
164164
}
165165

166166
- (IBAction)setExternalUserId:(UIButton *)sender {
167-
NSLog(@"setExternalUserId is no longer supported. Please use login or addAlias.");
167+
NSString* externalUserId = self.externalUserIdTextField.text;
168+
NSLog(@"Dev App: Logging in to external user ID %@", externalUserId);
169+
[OneSignal login:externalUserId];
168170
}
169171

170172
- (IBAction)removeExternalUserId:(UIButton *)sender {
171-
NSLog(@"setExternalUserId is no longer supported. Please use logout or removeAlias.");
173+
NSLog(@"Dev App: Logout called.");
174+
[OneSignal logout];
172175
}
173176

174177
#pragma mark UITextFieldDelegate Methods

iOS_SDK/OneSignalDevApp/OneSignalDevAppClip/OneSignalDevAppClip.entitlements

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</array>
1212
<key>com.apple.developer.parent-application-identifiers</key>
1313
<array>
14-
<string>$(AppIdentifierPrefix)com.onesignal.example</string>
14+
<string>$(AppIdentifierPrefix)com.onesignal.example.staging</string>
1515
</array>
1616
</dict>
1717
</plist>

iOS_SDK/OneSignalDevApp/OneSignalExample.xcodeproj/project.pbxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@
745745
);
746746
MARKETING_VERSION = 1.4.4;
747747
OTHER_LDFLAGS = "-ObjC";
748-
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example;
748+
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging;
749749
PRODUCT_NAME = OneSignalExample;
750750
SUPPORTS_MACCATALYST = YES;
751751
SWIFT_OBJC_BRIDGING_HEADER = "OneSignalDevApp/OneSignalExample-Bridging-Header.h";
@@ -776,7 +776,7 @@
776776
);
777777
MARKETING_VERSION = 1.4.4;
778778
OTHER_LDFLAGS = "-ObjC";
779-
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example;
779+
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging;
780780
PRODUCT_NAME = OneSignalExample;
781781
SUPPORTS_MACCATALYST = YES;
782782
SWIFT_OBJC_BRIDGING_HEADER = "OneSignalDevApp/OneSignalExample-Bridging-Header.h";
@@ -804,7 +804,7 @@
804804
);
805805
MARKETING_VERSION = 1.4.4;
806806
OTHER_LDFLAGS = "-ObjC";
807-
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.OneSignalNotificationServiceExtensionA;
807+
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging.OneSignalNotificationServiceExtensionA;
808808
PRODUCT_NAME = "$(TARGET_NAME)";
809809
SKIP_INSTALL = YES;
810810
SUPPORTS_MACCATALYST = YES;
@@ -832,7 +832,7 @@
832832
);
833833
MARKETING_VERSION = 1.4.4;
834834
OTHER_LDFLAGS = "-ObjC";
835-
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.OneSignalNotificationServiceExtensionA;
835+
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging.OneSignalNotificationServiceExtensionA;
836836
PRODUCT_NAME = "$(TARGET_NAME)";
837837
SKIP_INSTALL = YES;
838838
SUPPORTS_MACCATALYST = YES;
@@ -877,7 +877,7 @@
877877
MARKETING_VERSION = 1.4.4;
878878
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
879879
MTL_FAST_MATH = YES;
880-
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.Clip;
880+
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging.Clip;
881881
PRODUCT_NAME = OneSignalExampleClip;
882882
TARGETED_DEVICE_FAMILY = "1,2";
883883
};
@@ -915,7 +915,7 @@
915915
);
916916
MARKETING_VERSION = 1.4.4;
917917
MTL_FAST_MATH = YES;
918-
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.Clip;
918+
PRODUCT_BUNDLE_IDENTIFIER = com.onesignal.example.staging.Clip;
919919
PRODUCT_NAME = OneSignalExampleClip;
920920
TARGETED_DEVICE_FAMILY = "1,2";
921921
};

iOS_SDK/OneSignalDevApp/OneSignalNotificationServiceExtension/OneSignalNotificationServiceExtension.entitlements

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<dict>
55
<key>com.apple.security.application-groups</key>
66
<array>
7-
<string>group.com.onesignal.example.onesignal</string>
7+
<string>group.com.onesignal.example.staging.onesignal</string>
88
</array>
99
</dict>
1010
</plist>

iOS_SDK/OneSignalSDK/OneSignalUser/Source/OSUserRequests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class OSUserExecutor {
6363
}
6464

6565
/**
66-
Used to parse Create User and Fetch User responses. The `originalPushToken` is the push token when the request was created, which may be different from the push token currently in the SDK (How again can that happen?). This is used to determine whether or not to hydrate the push subscription.
66+
Used to parse Create User and Fetch User responses. The `originalPushToken` is the push token when the request was created, which may be different from the push token currently in the SDK. For example, when the request was created, there may be no push token yet, but soon after, the SDK receives a push token. This is used to determine whether or not to hydrate the push subscription.
6767
*/
6868
static func parseFetchUserResponse(response: [AnyHashable:Any], identityModel: OSIdentityModel, originalPushToken: String?) {
6969
// On success, check if the current user is the same as the one in the request

0 commit comments

Comments
 (0)