|
71 | 71 | #define ERROR_PUSH_CAPABLILITY_DISABLED -13 |
72 | 72 | #define ERROR_PUSH_DELEGATE_NEVER_FIRED -14 |
73 | 73 | #define ERROR_PUSH_SIMULATOR_NOT_SUPPORTED -15 |
74 | | -#define ERROR_PUSH_UNKNOWN_APNS_ERROR -16 |
| 74 | +#define ERROR_PUSH_UNKNOWN_APNS_ERROR -16 |
75 | 75 | #define ERROR_PUSH_OTHER_3000_ERROR -17 |
76 | 76 | #define ERROR_PUSH_NEVER_PROMPTED -18 |
77 | 77 | #define ERROR_PUSH_PROMPT_NEVER_ANSWERED -19 |
@@ -329,47 +329,19 @@ + (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId |
329 | 329 | // Ensure a 2nd call can be made later with the appId from the developer's code. |
330 | 330 | + (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId handleNotificationReceived:(OSHandleNotificationReceivedBlock)receivedCallback handleNotificationAction:(OSHandleNotificationActionBlock)actionCallback settings:(NSDictionary*)settings { |
331 | 331 |
|
332 | | - if (![[NSUUID alloc] initWithUUIDString:appId]) { |
333 | | - onesignal_Log(ONE_S_LL_FATAL, @"OneSignal AppId format is invalid.\nExample: 'b2f7f966-d8cc-11eg-bed1-df8f05be55ba'\n"); |
334 | | - return self; |
335 | | - } |
| 332 | + NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; |
336 | 333 |
|
337 | | - if ([@"b2f7f966-d8cc-11eg-bed1-df8f05be55ba" isEqualToString:appId] || [@"5eb5a37e-b458-11e3-ac11-000c2940e62c" isEqualToString:appId]) |
338 | | - onesignal_Log(ONE_S_LL_WARN, @"OneSignal Example AppID detected, please update to your app's id found on OneSignal.com"); |
| 334 | + bool success = [self initAppId:appId withUserDefaults:userDefaults withSettings:settings]; |
| 335 | + |
| 336 | + if (!success) |
| 337 | + return self; |
339 | 338 |
|
340 | 339 | if (mShareLocation) |
341 | 340 | [OneSignalLocation getLocation:false]; |
342 | 341 |
|
343 | 342 | if (self) { |
344 | | - NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults]; |
345 | | - |
346 | 343 | [OneSignalHelper notificationBlocks: receivedCallback : actionCallback]; |
347 | 344 |
|
348 | | - if (appId) |
349 | | - app_id = appId; |
350 | | - else { |
351 | | - // Read from .plist if not passed in with this method call. |
352 | | - app_id = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"OneSignal_APPID"]; |
353 | | - if (app_id == nil) |
354 | | - app_id = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"GameThrive_APPID"]; |
355 | | - } |
356 | | - |
357 | | - // Handle changes to the app id. This might happen on a developer's device when testing. |
358 | | - if (app_id == nil) |
359 | | - app_id = [userDefaults stringForKey:@"GT_APP_ID"]; |
360 | | - else if (![app_id isEqualToString:[userDefaults stringForKey:@"GT_APP_ID"]]) { |
361 | | - // Will run the first time OneSignal is initialized or if the dev changes the app_id. |
362 | | - [userDefaults setObject:app_id forKey:@"GT_APP_ID"]; |
363 | | - [userDefaults setObject:nil forKey:@"GT_PLAYER_ID"]; |
364 | | - [userDefaults synchronize]; |
365 | | - } |
366 | | - |
367 | | - if (!app_id) { |
368 | | - if (![settings[kOSSettingsKeyInOmitNoAppIdLogging] boolValue]) |
369 | | - onesignal_Log(ONE_S_LL_FATAL, @"OneSignal AppId never set!"); |
370 | | - return self; |
371 | | - } |
372 | | - |
373 | 345 | if ([OneSignalHelper isIOSVersionGreaterOrEqual:8]) |
374 | 346 | registeredWithApple = self.currentPermissionState.accepted; |
375 | 347 | else |
@@ -447,6 +419,40 @@ + (id)initWithLaunchOptions:(NSDictionary*)launchOptions appId:(NSString*)appId |
447 | 419 | return self; |
448 | 420 | } |
449 | 421 |
|
| 422 | ++(bool)initAppId:(NSString*)appId withUserDefaults:(NSUserDefaults*)userDefaults withSettings:(NSDictionary*)settings { |
| 423 | + if (appId) |
| 424 | + app_id = appId; |
| 425 | + else { |
| 426 | + // Read from .plist if not passed in with this method call. |
| 427 | + app_id = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"OneSignal_APPID"]; |
| 428 | + if (app_id == nil) |
| 429 | + app_id = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"GameThrive_APPID"]; |
| 430 | + } |
| 431 | + |
| 432 | + if (!app_id) { |
| 433 | + if (![settings[kOSSettingsKeyInOmitNoAppIdLogging] boolValue]) |
| 434 | + onesignal_Log(ONE_S_LL_FATAL, @"OneSignal AppId never set!"); |
| 435 | + app_id = [userDefaults stringForKey:@"GT_APP_ID"]; |
| 436 | + } |
| 437 | + else if (![app_id isEqualToString:[userDefaults stringForKey:@"GT_APP_ID"]]) { |
| 438 | + // Handle changes to the app id. This might happen on a developer's device when testing |
| 439 | + // Will also run the first time OneSignal is initialized |
| 440 | + [userDefaults setObject:app_id forKey:@"GT_APP_ID"]; |
| 441 | + [userDefaults setObject:nil forKey:@"GT_PLAYER_ID"]; |
| 442 | + [userDefaults synchronize]; |
| 443 | + } |
| 444 | + |
| 445 | + if (!app_id || ![[NSUUID alloc] initWithUUIDString:app_id]) { |
| 446 | + onesignal_Log(ONE_S_LL_FATAL, @"OneSignal AppId format is invalid.\nExample: 'b2f7f966-d8cc-11e4-bed1-df8f05be55ba'\n"); |
| 447 | + return false; |
| 448 | + } |
| 449 | + |
| 450 | + if ([@"b2f7f966-d8cc-11e4-bed1-df8f05be55ba" isEqualToString:appId] || [@"5eb5a37e-b458-11e3-ac11-000c2940e62c" isEqualToString:appId]) |
| 451 | + onesignal_Log(ONE_S_LL_WARN, @"OneSignal Example AppID detected, please update to your app's id found on OneSignal.com"); |
| 452 | + |
| 453 | + return true; |
| 454 | +} |
| 455 | + |
450 | 456 | + (void)setLogLevel:(ONE_S_LOG_LEVEL)nsLogLevel visualLevel:(ONE_S_LOG_LEVEL)visualLogLevel { |
451 | 457 | NSLog(@"ONESIGNAL - Setting log level: %d", (int)nsLogLevel); |
452 | 458 | _nsLogLevel = nsLogLevel; _visualLogLevel = visualLogLevel; |
|
0 commit comments