关于推送

// 推送相关
- (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);
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值