iOS APNS推送总结

一、APNS提供了两项基本的服务:

1. 消息推送

  • 测试接口:gateway.sandbox.push.apple.com:219
  • 产品接口:gateway.push.apple.com:2195

2. 反馈服务

  • 测试接口:sandbox:feedback.push.apple.com:2196
  • 产品接口:feedback.sandbox.push.apple.com:2196

二、APNS推送调用函数:

  • app未打开开启的情况下:app调用didFinishLaunchingWithOptions函数
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
        //判断程序是不是由推送服务完成的
        if (launchOptions) {   
         	//截取apns推送的消息
         	NSDictionary* pushInfo = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"]; 

         	//获取推送详情
         	NSString *pushInfo = [[NSString stringWithFormat:@"%@",[pushInfo  objectForKey:@"aps"]];
		}
}
  • app在后台运行时(Background状态):app调用didReceiveRemoteNotification函数
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
        // 可直接使用 [userInfo objectForKey:@"aps"] 获取推送消息

你可能感兴趣的:(iOS)