Skip to content

Commit 6c77587

Browse files
authored
Bundle ID Improvement (#377)
• In order to allow communication between the App Extension and the host/primary application, OneSignal SDK uses an app group to perform communication • For most developers, the name of the app group will simply be group.{your_bundle_id}.onesignal • The SDK can automatically retrieve this bundle ID, but previously, for the app extension service, this was broken because it was only retrieving the bundle ID for the OneSignalNotificationServiceExtension • This means the bundle ID's would not have matched and badge count would be inconsistent. This commit fixes the issue by using a method to retrieve the host app's bundle ID.
1 parent 54f9a19 commit 6c77587

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

iOS_SDK/OneSignalDevApp/OneSignalDevApp/AppDelegate.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
5959

6060
id notificationReceiverBlock = ^(OSNotification *notification) {
6161
NSLog(@"Received Notification - %@", notification.payload.notificationID);
62-
63-
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:11];
6462
};
6563

6664
[OneSignal initWithLaunchOptions:launchOptions

iOS_SDK/OneSignalDevApp/OneSignalDevApp/Info.plist

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5-
<key>OneSignal_require_privacy_consent</key>
6-
<true/>
75
<key>CFBundleDevelopmentRegion</key>
86
<string>en</string>
97
<key>CFBundleExecutable</key>
@@ -31,10 +29,8 @@
3129
<string>Test Location</string>
3230
<key>NSLocationWhenInUseUsageDescription</key>
3331
<string>Test Location2</string>
34-
<key>OneSignal_app_groups_key</key>
35-
<string> group.com.onesignal.example.testgroup </string>
36-
<key>OneSignal_disable_badge_clearing</key>
37-
<true/>
32+
<key>OneSignal_require_privacy_consent</key>
33+
<false/>
3834
<key>UIBackgroundModes</key>
3935
<array>
4036
<string>remote-notification</string>
@@ -47,6 +43,8 @@
4743
<array>
4844
<string>armv7</string>
4945
</array>
46+
<key>OneSignal_disable_badge_clearing</key>
47+
<false/>
5048
<key>UISupportedInterfaceOrientations</key>
5149
<array>
5250
<string>UIInterfaceOrientationPortrait</string>

iOS_SDK/OneSignalDevApp/OneSignalNotificationServiceExtension/Info.plist

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5-
<key>OneSignal_app_groups_key</key>
6-
<string>group.com.onesignal.example.testgroup</string>
75
<key>CFBundleDevelopmentRegion</key>
86
<string>en</string>
97
<key>CFBundleDisplayName</key>

iOS_SDK/OneSignalSDK/Source/OneSignalExtensionBadgeHandler.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ + (NSInteger)currentCachedBadgeValue {
6363
return [(NSNumber *)[userDefaults objectForKey:ONESIGNAL_BADGE_KEY] integerValue];
6464
}
6565

66+
//gets the NSBundle of the primary application - NOT the app extension
67+
//this way we can determine the bundle ID for the host (primary) application.
68+
+ (NSString *)primaryBundleIdentifier {
69+
NSBundle *bundle = [NSBundle mainBundle];
70+
if ([[bundle.bundleURL pathExtension] isEqualToString:@"appex"])
71+
bundle = [NSBundle bundleWithURL:[[bundle.bundleURL URLByDeletingLastPathComponent] URLByDeletingLastPathComponent]];
72+
73+
return [bundle bundleIdentifier];
74+
75+
}
76+
6677
+ (void)updateCachedBadgeValue:(NSInteger)value {
6778
//since badge logic can be executed in an extension, we need to use app groups to get
6879
//a shared NSUserDefaults from the app group suite name
@@ -77,7 +88,7 @@ + (NSString *)appGroupName {
7788
var appGroupName = (NSString *)[[NSBundle mainBundle] objectForInfoDictionaryKey:ONESIGNAL_APP_GROUP_NAME_KEY];
7889

7990
if (!appGroupName)
80-
appGroupName = [NSString stringWithFormat:@"group.%@.%@", [[NSBundle mainBundle] bundleIdentifier], @"onesignal"];
91+
appGroupName = [NSString stringWithFormat:@"group.%@.%@", OneSignalExtensionBadgeHandler.primaryBundleIdentifier, @"onesignal"];
8192

8293
return [appGroupName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
8394
}

0 commit comments

Comments
 (0)