远程推送代码的添加
项目一添加方式;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法 中加入要调用的推送
推送分iOS8来处理
项目二添加方式;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法 中加入要调用的推送
项目三添加方式;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法 中加入要调用的推送
代码对比
项目一中的推送代码
#pragma mark XGPush - (void)registerPush{ float sysVer = [[[UIDevice currentDevice] systemVersion] floatValue]; if(sysVer < 8){ [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; }else{ #if __IPHONE_OS_VERSION_MAX_ALLOWED >= _IPHONE80_ UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc] init]; UIUserNotificationSettings *userSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:[NSSet setWithObject:categorys]]; [[UIApplication sharedApplication] registerUserNotificationSettings:userSettings]; [[UIApplication sharedApplication] registerForRemoteNotifications]; #endif } }
项目二中的推送代码
#pragma mark - 推送注册函数(并选择注册的推送消息类型) - (void)registerNotificationType { #ifdef __IPHONE_8_0 if(SystemVersion >= 8.0) { [[UIApplication sharedApplication] registerForRemoteNotifications]; /** * @author zyz * * 对应8系统后,系统推送服务 */ // UIUserNotificationTypeBadge // UIUserNotificationTypeSound // UIUserNotificationTypeAlert UIUserNotificationType myTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert; UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:myTypes categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; } else #endif { [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; } }
项目三中的推送代码
- (void)registerForRemoteNotifications { #if SUPPORT_IOS8 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { UIUserNotificationType myTypes = UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound; UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:myTypes categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; }else #endif { UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound; [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes]; } /* #if TARGET_OS_IPHONE #if SUPPORT_IOS8 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) { UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:myTypes categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; }else #endif { [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; } #endif */ }
#if SUPPORT_IOS8 - (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings { //register to receive notifications [application registerForRemoteNotifications]; } #endif