iOS 远程推送

(https://img-blog.csdn.net/20151002162027055)

iOS远程通知:
1、后台推送通知到苹果服务器(APNS)
2、苹果服务器(APNS)把通知发送到苹果手机端
3、手机接收通知

1)、后台推送通知到苹果服务器(APNS)
下载一个APNS的证书, 用PHP写的后台 是.pem文件 如果是java/.net.p12
1、下载APNS证书:一个应用必须要有一个与他对应的证书bundleID
(1)申请APNS证书的时候 需要填写一个appID与app的bundleID对应
https://developer.apple.com/
这个证书可以通过我们前面生成的两个文件中得到。

1、将aps_developer_identity.cer转换成aps_developer_identity.pem格式

  1. openssl x509 -in aps_developer_identity.cer -inform DER -out aps_developer_identity.pem -outform PEM

2、将p12格式的私钥转换成pem

  1. openssl pkcs12 -nocerts -out Push_Noenc.pem -in Push.p12

3、创建p12文件

  1. openssl pkcs12 -export -in aps_developer_identity.pem -inkey Push_Noenc.pem -certfile Push.certSigningRequest -name “aps_developer_identity” -out aps_developer_identity.p12

这样我们就得到了在.net或java等后台应用程序中使用的证书文件:aps_developer_identity.p12

二、苹果服务器(APNS)把通知发送到苹果手机端

需要提供给后台服务器一个deviceToken号 以及通知的内容一同发送给苹果服务器

iOS添加代码如下:

三、手机接收通知

1、注册通知

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {

    UIMutableUserNotificationCategory *categorys = [[UIMutableUserNotificationCategory alloc]init];

    categorys.identifier=@"Bruce.com.Where";



    UIUserNotificationSettings *userNotifiSetting = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound) categories:[NSSet setWithObjects:categorys,nil]];



    [[UIApplication sharedApplication] registerUserNotificationSettings:userNotifiSetting];



    [[UIApplication sharedApplication] registerForRemoteNotifications];

}else {

    //注册远程推送

    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

}

添加到didFinishLaunchingWithOptions

2、应用程序内部 提示通知

当接受到远程通知 就会自动调用

-(void)application:(UIApplication )application didReceiveRemoteNotification:(NSDictionary )userInfo{

userInfo 包含了 具体通知的内容
}

全部搞定之后 还需设置XCode

这个证书可以通过我们前面生成的两个文件中得到。

1、将aps_developer_identity.cer转换成aps_developer_identity.pem格式

  1. openssl x509 -in aps_developer_identity.cer -inform DER -out aps_developer_identity.pem -outform PEM

2、将p12格式的私钥转换成pem

  1. openssl pkcs12 -nocerts -out Push_Noenc.pem -in Push.p12

3、创建p12文件

  1. openssl pkcs12 -export -in aps_developer_identity.pem -inkey Push_Noenc.pem -certfile Push.certSigningRequest -name “aps_developer_identity” -out aps_developer_identity.p12

这样我们就得到了在.net或java等后台应用程序中使用的证书文件:aps_developer_identity.p12

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ldl_csdn_ios

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值