且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

iOS书报摊:推送通知不会在后台启动应用程序

更新时间:2023-01-04 21:35:08

一些说明

  1. 如果您未在报亭有效载荷中发送警报", 仅内容可用:1,不会添加任何内容 通知中心.
  2. 报亭通知启动应用程序并不意味着该应用程序会出现在前台(就像用户在应用程序图标上轻按一样).这只是意味着,如果该应用程序不在后台,它将由iOS在后台启动->调用appDelegate的didFinishLaunchingWithOptions,在此应用程序应检查是否是报亭通知,以通过在报亭队列中添加资产来安排下载.资产路径可以是NS有效负载的一部分(提供的有效负载限制为
  1. If you do not send "alert" in your Newsstand payload which has only content-available:1 in it, nothing will get added in notification center.
  2. Newsstand notification launch application does not mean the app will come to foreground (as in if user tapped over app icon). It just mean that if the app is not in background, it will get launched by iOS in background -> didFinishLaunchingWithOptions of appDelegate is called, where app should check if it is a Newsstand notification to schedule the download by adding assets in Newsstand queue. The asset paths can be part of NS payload (provided < payload limit 256 bytes)

NSDictionary *有效载荷= [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

NSDictionary *payload = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

if(有效载荷&& [[有效载荷objectForKey:kContentAvailablePush] caseInsensitiveCompare:@"1"] == NSOrderedSame) { NSLog(@由于NS通知而启动"); }

if(payload && [[payload objectForKey:kContentAvailablePush] caseInsensitiveCompare:@"1"] == NSOrderedSame) { NSLog(@"Launched due to NS notification"); }