For iOS 10 using xCode 8 GM.
I solved the problem with the following steps using xCode 8 GM for iOS 10:
1) For targeted purposes, in the "Features" section, click "Push Notifications" to add Push Push notifications.
2) Embed UserNotifications.framework in your application. Import UserNotifications.framework into AppDelegate.
#import <UserNotifications/UserNotifications.h> @interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate> @end
3) In the didFinishLaunchingWithOptions method, assign UIUserNotificationSettings and run the UNUserNotificationCenter delegate.
#define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")){ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){ if( !error ){ [[UIApplication sharedApplication] registerForRemoteNotifications]; } }]; } return YES; }
4) Now, finally, we implement two delegate methods.
// ============= For iOS 10 ==============
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
Please stay in the code since it is used for iOS 9. Only add lines of code to support push notifications for iOS 10 with UserNotifications.framework.
Ashish Shah Sep 15 '16 at 8:36 2016-09-15 08:36
source share