Skip to content

Commit a1fba3d

Browse files
committed
Error checking for nil appId on first run.
* Added “kOSSettingsKeyInOmitNoAppIdLogging” setting so wrapper SDKs don’t trigger this log entry.
1 parent b09d2a4 commit a1fba3d

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

OneSignal.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "OneSignal"
3-
s.version = "2.3.2"
3+
s.version = "2.3.3"
44
s.summary = "OneSignal push notification library for mobile apps."
55
s.homepage = "https://onesignal.com"
66
s.license = { :type => 'MIT', :file => 'LICENSE' }
6.45 KB
Binary file not shown.

iOS_SDK/OneSignal/OneSignal.m

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,23 @@
6868
static ONE_S_LOG_LEVEL _nsLogLevel = ONE_S_LL_WARN;
6969
static ONE_S_LOG_LEVEL _visualLogLevel = ONE_S_LL_NONE;
7070

71-
NSString * const kOSSettingsKeyAutoPrompt = @"kOSSettingsKeyAutoPrompt";
71+
NSString* const kOSSettingsKeyAutoPrompt = @"kOSSettingsKeyAutoPrompt";
7272

73-
/*Enable the default in-app alerts*/
74-
NSString * const kOSSettingsKeyInAppAlerts = @"kOSSettingsKeyInAppAlerts";
73+
/* Enable the default in-app alerts*/
74+
NSString* const kOSSettingsKeyInAppAlerts = @"kOSSettingsKeyInAppAlerts";
7575

76-
/*Enable the default in-app launch urls*/
77-
NSString * const kOSSettingsKeyInAppLaunchURL = @"kOSSettingsKeyInAppLaunchURL";
76+
/* Enable the default in-app launch urls*/
77+
NSString* const kOSSettingsKeyInAppLaunchURL = @"kOSSettingsKeyInAppLaunchURL";
7878

7979
/* Set InFocusDisplayOption value must be an OSNotificationDisplayType enum*/
80-
NSString * const kOSSettingsKeyInFocusDisplayOption = @"kOSSettingsKeyInFocusDisplayOption";
80+
NSString* const kOSSettingsKeyInFocusDisplayOption = @"kOSSettingsKeyInFocusDisplayOption";
81+
82+
/* Omit no app_id error logging, for use with wrapper SDKs. */
83+
NSString* const kOSSettingsKeyInOmitNoAppIdLogging = @"kOSSettingsKeyInOmitNoAppIdLogging";
8184

8285
@implementation OneSignal
8386

84-
NSString* const ONESIGNAL_VERSION = @"020302";
87+
NSString* const ONESIGNAL_VERSION = @"020303";
8588
static NSString* mSDKType = @"native";
8689
static BOOL coldStartFromTapOnNotification = NO;
8790

@@ -140,6 +143,8 @@ + (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId
140143
return [self initWithLaunchOptions: launchOptions appId: appId handleNotificationReceived: NULL handleNotificationAction : actionCallback settings: settings];
141144
}
142145

146+
// NOTE: Wrapper SDKs such as Unity3D will call this method with appId set to nil so open events are not lost.
147+
// Ensure a 2nd call can be made later with the appId from the developer's code.
143148
+ (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId handleNotificationReceived:(OSHandleNotificationReceivedBlock)receivedCallback handleNotificationAction:(OSHandleNotificationActionBlock)actionCallback settings:(NSDictionary*)settings {
144149

145150
if (![[NSUUID alloc] initWithUUIDString:appId]) {
@@ -150,35 +155,42 @@ + (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId
150155
if ([@"b2f7f966-d8cc-11eg-bed1-df8f05be55ba" isEqualToString:appId] || [@"5eb5a37e-b458-11e3-ac11-000c2940e62c" isEqualToString:appId])
151156
onesignal_Log(ONE_S_LL_WARN, @"OneSignal Example AppID detected, please update to your app's id found on OneSignal.com");
152157

153-
if (mShareLocation) {
158+
if (mShareLocation)
154159
[OneSignalLocation getLocation:false];
155-
}
156160

157161
if (self) {
158162
UIApplication* sharedApp = [UIApplication sharedApplication];
159163
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
160164

165+
httpClient = [[OneSignalHTTPClient alloc] init];
166+
161167
[OneSignalHelper notificationBlocks: receivedCallback : actionCallback];
162168

163169
if (appId)
164170
app_id = appId;
165171
else {
166-
app_id =[[NSBundle mainBundle] objectForInfoDictionaryKey:@"OneSignal_APPID"];
172+
// Read from .plist if not passed in with this method call.
173+
app_id = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"OneSignal_APPID"];
167174
if (app_id == nil)
168175
app_id = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"GameThrive_APPID"];
169176
}
170177

171-
httpClient = [[OneSignalHTTPClient alloc] init];
172-
173178
// Handle changes to the app id. This might happen on a developer's device when testing.
174179
if (app_id == nil)
175180
app_id = [userDefaults stringForKey:@"GT_APP_ID"];
176181
else if (![app_id isEqualToString:[userDefaults stringForKey:@"GT_APP_ID"]]) {
182+
// Will run the first time OneSignal is initialized or if the dev changes the app_id.
177183
[userDefaults setObject:app_id forKey:@"GT_APP_ID"];
178184
[userDefaults setObject:nil forKey:@"GT_PLAYER_ID"];
179185
[userDefaults synchronize];
180186
}
181187

188+
if (!app_id) {
189+
if (!settings[kOSSettingsKeyInAppLaunchURL])
190+
onesignal_Log(ONE_S_LL_FATAL, @"OneSignal AppId never set!");
191+
return self;
192+
}
193+
182194
mUserId = [userDefaults stringForKey:@"GT_PLAYER_ID"];
183195
mDeviceToken = [userDefaults stringForKey:@"GT_DEVICE_TOKEN"];
184196
if (([sharedApp respondsToSelector:@selector(currentUserNotificationSettings)]))
@@ -195,7 +207,7 @@ + (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId
195207

196208
// Register this device with Apple's APNS server if enabled auto-prompt or not passed a NO
197209
BOOL autoPrompt = YES;
198-
if(settings[kOSSettingsKeyAutoPrompt] && [settings[kOSSettingsKeyAutoPrompt] isKindOfClass:[NSNumber class]])
210+
if (settings[kOSSettingsKeyAutoPrompt] && [settings[kOSSettingsKeyAutoPrompt] isKindOfClass:[NSNumber class]])
199211
autoPrompt = [settings[kOSSettingsKeyAutoPrompt] boolValue];
200212
if (autoPrompt || registeredWithApple)
201213
[self registerForPushNotifications];

0 commit comments

Comments
 (0)