当一个ios 的push消息到来的时候,有两种情况,apple为我们提供了2个回调api来处理:
1.app 未启动状态
application:didFinishLaunchingWithOptions
//launchOptions 包含 推送 playload 信息
if (launchOptions != nil)
{
NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
NSLog(@"Launched from push notification: %@", dictionary);
//根据 playload内容处理
[self addMessageFromRemoteNotification:dictionary updateUI:NO];
}
}
2.app 运行状态
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
NSLog(@"Received notification: %@", userInfo);
[self addMessageFromRemoteNotification:userInfo updateUI:YES];
}
自定义消息内容
{
"aps": {
"alert": "hello users update .",
"badge": 1,
"sound": "default"
},
"page":"chat"
}
可以在消息自定义字段内容,然后在回调函数里判断处理