ios 通知 apns

默认情况下app在后台或者未启动 是拿不到通知信息的;如果app要在后台(或者前台不活跃)拿到通知信息 需要在apns的aps中加上content-available = 1 并且在项目的target-capabilities-Background mode中同时开启background fetch 和remote notifications ;在appdelegate中实现- (void)application:(UIApplication *)application

didReceiveRemoteNotification:(NSDictionary *)userInfo

fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler 方法,其中可以在后台或者前台,前台不活跃可以拿到通知信息。


ios 通知 apns_第1张图片


ios 通知 apns_第2张图片

tips:1、如果app未启动,无法拿到通知信息。

2、aps-alert 为空的时候手机app上不会显示条幅

3、app 未启动-点击通知进入 会在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中拿到

NSDictionary* remoteNotificationDict = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

4、app未启动-点击icon进入app 无法拿到通知信息

5、app在后台 - 点击通知进入(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo会在你的程序进入前台后才会被调用

6、app在后台 -  点击icon进入app (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 不会再次执行(但是在收到通知是会执行 - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler )

7、有标题  aps = {

        alert =        {

            body = "Your message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message Here";

            title = "Your message Here";

        };

        "content-available" = 1;

        sound = default;

    };

}


8、没标题 aps = {

        alert = "Your message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message HereYour message Here";

        "content-available" = 1;

        sound = default;

    };

}

参考链接 http://www.cocoachina.com/bbs/read.php?tid-290239-page-1.html

你可能感兴趣的:(ios 通知 apns)