ios8注册推送通知

来源:互联网 发布:网站环境搭建linux 编辑:程序博客网 时间:2024/05/17 03:28

    if ([[[UIDevicecurrentDevice] systemVersion]floatValue] >= 8.0)

    {

        [[UIApplicationsharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound |UIUserNotificationTypeAlert | UIUserNotificationTypeBadge)categories:nil]];

        

        //[[UIApplication sharedApplication] registerForRemoteNotifications];

    }

   else

    {

        UIRemoteNotificationType types =(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert);

        [[UIApplicationsharedApplication]registerForRemoteNotificationTypes:types];

    }


//获取DeviceToken成功

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken

{

    //保存deviceToken

   NSString *tokenStr = [deviceToken description];

    NSString *pushToken = [[[tokenStrstringByReplacingOccurrencesOfString:@"<"withString:@""]

                            stringByReplacingOccurrencesOfString:@">"withString:@""]

                           stringByReplacingOccurrencesOfString:@" "withString:@""];

   NSLog(@"pushToken..%@",pushToken);

}


//注册消息推送失败--Token值获取失败

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error

{

    //NSLog(@"Register Remote Notifications error:{%@}",[errorlocalizedDescription]);

   NSLog(@"%@",error);

}



0 0
原创粉丝点击