IOS远程推送基础

来源:互联网 发布:供应链反应矩阵 编辑:程序博客网 时间:2024/04/28 13:51


 

1. 创建支持远程推送功能的App ID

2. 申请开发者证书,并选中刚刚创建的App ID

3. 下载CER文件,并导入钥匙串管理

4. 申请发布证书,并选中刚刚创建的App ID

5. 下载CER文件,并导入钥匙串管理

6. 检查App ID,确认证书已经指定

 

格式:{"aps":{"alert":"This is somefancy message.","badge":1,"sound":"default"}}

 

远程推送应用程序开发过程

1. 新建应用程序

2. 指定AppID,在developer.apple.com上设置的AppID

 

#ifdef__IPHONE_8_0

    //注册接收通知的类型

   UIUserNotificationSettings *settings = [UIUserNotificationSettingssettingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge |UIUserNotificationTypeSound categories:nil];

   [application registerUserNotificationSettings:settings];

   

    //注册允许接收远程推送通知

   [application registerForRemoteNotifications];

#else

    //如果是iOS7.0,使用以下方法注册

   [application registerForRemoteNotificationTypes:UIUserNotificationTypeAlert |UIUserNotificationTypeBadge | UIUserNotificationTypeSound];

#endif

 

 

//当得到苹果的APNs服务器返回的DeviceToken就会被调用

- (void)application:(UIApplication *)applicationdidRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

   NSLog(@"deviceToken是:%@",deviceToken);

}

 

//接收到远程通知,触发方法和本地通知一致

- (void)application:(UIApplication *)applicationdidReceiveRemoteNotification:(NSDictionary *)userInfo {

   NSLog(@"%@", userInfo);

}

0 0
原创粉丝点击