IOS 消息推送处理

当一个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"
}
可以在消息自定义字段内容,然后在回调函数里判断处理
    原文作者:hqman
    原文地址: https://segmentfault.com/a/1190000003065116
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞