當一個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"
}
能夠在消息自定義字段內容,而後在回調函數裏判斷處理