@@ -275,34 +275,61 @@ - (BOOL)application:(UIApplication *)p_application didFinishLaunchingWithOptions
275275 // Get the info dictionary.
276276 NSDictionary *t_info_dict;
277277 t_info_dict = [[NSBundle mainBundle ] infoDictionary ];
278-
279- // Read the allowed notification types from the plist.
280- NSArray *t_allowed_push_notifications_array;
281- t_allowed_push_notifications_array = [t_info_dict objectForKey: @" CFSupportedRemoteNotificationTypes" ];
282- UIRemoteNotificationType t_allowed_notifications = UIRemoteNotificationTypeNone;
283- if (t_allowed_push_notifications_array != nil )
284- {
285- for (NSString *t_push_notification_string in t_allowed_push_notifications_array)
286- {
287- if ([t_push_notification_string isEqualToString: @" CFBadge" ])
288- t_allowed_notifications = (UIRemoteNotificationType) (t_allowed_notifications | UIRemoteNotificationTypeBadge);
289- else if ([t_push_notification_string isEqualToString: @" CFSound" ])
290- t_allowed_notifications = (UIRemoteNotificationType) (t_allowed_notifications | UIRemoteNotificationTypeSound);
291- else if ([t_push_notification_string isEqualToString: @" CFAlert" ])
292- t_allowed_notifications = (UIRemoteNotificationType) (t_allowed_notifications | UIRemoteNotificationTypeAlert);
293- }
294- }
295278
296- // IM-2012-02-13 don't try to register if there are no allowed push notification types
297- if (t_allowed_notifications != UIRemoteNotificationTypeNone)
279+ // Read the allowed notification types from the plist.
280+ NSArray *t_allowed_push_notifications_array;
281+ t_allowed_push_notifications_array = [t_info_dict objectForKey: @" CFSupportedRemoteNotificationTypes" ];
282+
283+ if (t_allowed_push_notifications_array != nil )
298284 {
299- // Inform the device what kind of push notifications we can handle.
300-
301- // MW-2013-07-29: [[ Bug 10979 ]] Dynamically call the 'registerForRemoteNotificationTypes' to
302- // avoid app-store warnings.
303- objc_msgSend ([UIApplication sharedApplication ], sel_getUid (" registerForRemoteNotificationTypes:" ), t_allowed_notifications);
285+ // MM-2014-09-30: [[ iOS 8 Support ]] Use new iOS 8 registration methods for push notifications.
286+ if (![[UIApplication sharedApplication ] respondsToSelector :@selector (registerUserNotificationSettings: )])
287+ {
288+ UIRemoteNotificationType t_allowed_notifications = UIRemoteNotificationTypeNone;
289+ for (NSString *t_push_notification_string in t_allowed_push_notifications_array)
290+ {
291+ if ([t_push_notification_string isEqualToString: @" CFBadge" ])
292+ t_allowed_notifications = (UIRemoteNotificationType) (t_allowed_notifications | UIRemoteNotificationTypeBadge);
293+ else if ([t_push_notification_string isEqualToString: @" CFSound" ])
294+ t_allowed_notifications = (UIRemoteNotificationType) (t_allowed_notifications | UIRemoteNotificationTypeSound);
295+ else if ([t_push_notification_string isEqualToString: @" CFAlert" ])
296+ t_allowed_notifications = (UIRemoteNotificationType) (t_allowed_notifications | UIRemoteNotificationTypeAlert);
297+ }
298+
299+ // IM-2012-02-13 don't try to register if there are no allowed push notification types
300+ if (t_allowed_notifications != UIRemoteNotificationTypeNone)
301+ {
302+ // Inform the device what kind of push notifications we can handle.
303+
304+ // MW-2013-07-29: [[ Bug 10979 ]] Dynamically call the 'registerForRemoteNotificationTypes' to
305+ // avoid app-store warnings.
306+ objc_msgSend ([UIApplication sharedApplication ], sel_getUid (" registerForRemoteNotificationTypes:" ), t_allowed_notifications);
307+ }
308+ }
309+ #ifdef __IPHONE_8_0
310+ else
311+ {
312+ UIUserNotificationType t_allowed_notifications;
313+ t_allowed_notifications = UIUserNotificationTypeNone;
314+ for (NSString *t_push_notification_string in t_allowed_push_notifications_array)
315+ {
316+ if ([t_push_notification_string isEqualToString: @" CFBadge" ])
317+ t_allowed_notifications = (UIRemoteNotificationType) (t_allowed_notifications | UIUserNotificationTypeBadge);
318+ else if ([t_push_notification_string isEqualToString: @" CFSound" ])
319+ t_allowed_notifications = (UIRemoteNotificationType) (t_allowed_notifications | UIUserNotificationTypeSound);
320+ else if ([t_push_notification_string isEqualToString: @" CFAlert" ])
321+ t_allowed_notifications = (UIRemoteNotificationType) (t_allowed_notifications | UIUserNotificationTypeAlert);
322+ }
323+ if (t_allowed_notifications != UIUserNotificationTypeNone)
324+ {
325+ UIUserNotificationSettings *t_push_settings;
326+ t_push_settings = [UIUserNotificationSettings settingsForTypes: t_allowed_notifications categories: nil ];
327+ [[UIApplication sharedApplication ] registerUserNotificationSettings: t_push_settings];
328+ }
329+ }
330+ #endif
304331 }
305-
332+
306333 // MM-2014-09-26: [[ iOS 8 Support ]] Move the registration for orientation updates to here from init. Was causing issues with iOS 8.
307334 // Tell the device we want orientation notifications.
308335 [[UIDevice currentDevice ] beginGeneratingDeviceOrientationNotifications ];
@@ -314,6 +341,15 @@ - (BOOL)application:(UIApplication *)p_application didFinishLaunchingWithOptions
314341 object: nil ];
315342}
316343
344+ // MM-2014-09-30: [[ iOS 8 Support ]] Method called after successully registering (push) notification settings.
345+ // Call registerForRemoteNotifications to finish off push notification registration process. (Will send didRegisterForRemoteNotificationsWithDeviceToken which will be handled as before.)
346+ #ifdef __IPHONE_8_0
347+ - (void )application : (UIApplication *)p_application didRegisterUserNotificationSettings : (UIUserNotificationSettings *)p_notificationSettings
348+ {
349+ [p_application registerForRemoteNotifications ];
350+ }
351+ #endif
352+
317353- (void )application : (UIApplication *)p_application didReceiveLocalNotification : (UILocalNotification *)p_notification
318354{
319355 MCLog (" application:didReceiveLocalNotification:" );
0 commit comments