// 推送相关
- (void)pushWithApplication:(UIApplication *)application launchOptions:(NSDictionary *)launchOptions
{
if ([UIDevice currentDevice].systemVersion.doubleValue <= 8.0) {
// iOS8之前
UIRemoteNotificationType type = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert;
[application registerForRemoteNotificationTypes:type];
} else {
// iOS8之后
UIUserNotificationType type = UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
}
// 如果应用程序是关闭状态会调用这里
NSDictionary *userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
FNLog(@"userInfo = %@", userInfo);
}
// 获取设备的deviceToken
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
FNLog(@"deviceToken = %@", deviceToken);
}
// 接收到服务器推送过来的消息会调用此方法 iOS7之前
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if (userInfo) {
}
}
// 接收到服务器推送过来的消息会调用此方法 iOS7以后
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
// completionHandler 这个block必须调用,因为系统后台会更新一些东西
if (userInfo) {
// 有新数据 接收推送消息成功
completionHandler(UIBackgroundFetchResultNewData);
} else {
// 接收推送消息失败
completionHandler(UIBackgroundFetchResultFailed);
}
}
- (void)pushWithApplication:(UIApplication *)application launchOptions:(NSDictionary *)launchOptions
{
if ([UIDevice currentDevice].systemVersion.doubleValue <= 8.0) {
// iOS8之前
UIRemoteNotificationType type = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert;
[application registerForRemoteNotificationTypes:type];
} else {
// iOS8之后
UIUserNotificationType type = UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound;
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
}
// 如果应用程序是关闭状态会调用这里
NSDictionary *userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
FNLog(@"userInfo = %@", userInfo);
}
// 获取设备的deviceToken
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
FNLog(@"deviceToken = %@", deviceToken);
}
// 接收到服务器推送过来的消息会调用此方法 iOS7之前
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if (userInfo) {
}
}
// 接收到服务器推送过来的消息会调用此方法 iOS7以后
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
// completionHandler 这个block必须调用,因为系统后台会更新一些东西
if (userInfo) {
// 有新数据 接收推送消息成功
completionHandler(UIBackgroundFetchResultNewData);
} else {
// 接收推送消息失败
completionHandler(UIBackgroundFetchResultFailed);
}
}