关于iOS推送通知前端需要的操作

前端其实需要的操作非常少,(前端的配置文件,证书必须和服务器上面的推送证书是用 都一个 csr 生成的)

1. 注册推送通知        

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

2.获取token的方法

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
    
    NSString *str =[NSString stringWithFormat:@"%@",deviceToken];
    str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
    str = [str substringWithRange:NSMakeRange(1,64)];
    
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    [accountDefaults setObject:str forKey:@"token"];
}

 

苹果apns推送总结

一、APNS提供了两项基本的服务:消息推送和反馈服务。


消息推送

测试接口:gateway.sandbox.push.apple.com:2196

产品接口:gateway.push.apple.com:2195

反馈服务

测试接口:feedback.sandbox.push.apple.com2196

产品接口:feedback.push.apple.com:2195

二、APNS推送调用函数


    app未打开开启的情况下:app调用didFinishLaunchingWithOptions函数

    app在后台运行时(backGround状态):app调用didReceiveRemoteNotification函数


三、apns推送且传送指定参数:


关键注意点


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

        可直接使用 [userInfo objectForKey:@"aps"] 获取推送消息

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  

        接收推送消息是不能直接使用 [userInfo objectForKey:@"aps"] 获取,需用一下fang's

        //判断程序是不是由推送服务完成的

        if (launchOptions) {   

        //截取apns推送的消息

                NSDictionary* pushInfo = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"]; 

        //获取推送详情

        NSString *pushInfo = [[NSString stringWithFormat:@"%@",[pushInfo  objectForKey:@"aps"]];

}

posted @ 2013-07-29 11:19  S小亮  阅读(537)  评论(0编辑  收藏  举报