首页 技术 正文
技术 2022年11月13日
0 收藏 830 点赞 3,627 浏览 1407 个字

服务器向客户端推送消息:     当应用程序推到后台,或者根本就没有运行(我们的代码无能为力)
     如果这种情况之下,应用程序想和用户交互(传统的做法 不可能)    推送APNS:Apple Push Notification ServicedeviceToken:标示某一台iPhone上的某一个应用程序
      1.(用户必须确认需要收到推送消息)注册远程通知中心向APNS获取64位的字符串deviceToken          注册远程通知中心          [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
          参数:          UIRemoteNotificationTypeBadge     //应用程序的角标
          UIRemoteNotificationTypeSound     //推送提示音

UIRemoteNotificationTypeAlert     //提示框内容

     2.APNS返回deviceToken(进入代理方法)          1)成功获取deviceToken,系统回调          – (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;           2)获取deviceToken失败,系统回调          – (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;      3.iPhone将deviceToken上传至服务器(POST)          例:          deviceToken: <c389e769 d6ddb7d5 a783a015 ff553d90 5b1e04e2 6fa71ec7 f0aa52ab 4bdcc660>          1.处理字符串,消除空格 和 <>          2.得到位字符串,post至服务器      4.服务器将推送的消息+deviceToken+(SSL & privace key(两个生成一个文件))发送到APNS      5.(验证通过后)APNS将消息发送到iPhone      6.用户点击推送通知,系统回调(在此方法里将角标置零)     – (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;     参数:          userInfo:包含推送的内容+推送的声音+角标签           1)设置角标          @property(nonatomic) NSInteger applicationIconBadgeNumber;  推送需要证书:该证书是2份  一份给客户端  一份给服务器(客户端的服务器)
服务器和客户端推送证书必须一致

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,910
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,498
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,135
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,298