簡體   English   中英

iOS書報攤:推送通知不會在后台啟動應用程序

[英]iOS newsstand: push notification does not launch the app in background

我正在應用程序中實現報亭功能,盡管該應用程序收到推送通知,但它不是在后台模式下啟動。
如果我點擊通知警報,該應用程序將啟動,並且我會看到“內容可用”:1存在於詞典中,並且該問題也已下載,但該應用程序不會自動啟動。

我已添加到plist中:

<key>UIBackgroundModes</key>
<array>
    <string>newsstand-content</string>
</array>

並執行didFinishLaunchingWithOptions:

[[NSUserDefaults standardUserDefaults]setBool: YES forKey:@"NKDontThrottleNewsstandContentNotifications"]; // for testing purposes
    [[NSUserDefaults standardUserDefaults] synchronize];

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeNewsstandContentAvailability )];

我還看到我的應用程序未顯示在“設置”->“商店”->“自動下載”下(其他雜志出現在此處)。

我想念什么嗎? 這應該在沙盒環境中工作嗎?

一些澄清

  1. 如果您沒有在報亭有效載荷中發送僅包含內容可用的“警報”:1,則通知中心將不會添加任何內容。
  2. 報亭通知啟動應用程序並不意味着該應用程序會進入前台(就像用戶點擊應用程序圖標一樣)。 這僅表示如果該應用程序不在后台,它將由iOS在后台啟動->調用appDelegate的didFinishLaunchingWithOptions,在該應用程序中應檢查是否是報亭通知,以通過在報亭隊列中添加資產來安排下載。 資產路徑可以是NS有效負載的一部分(提供的<有效負載限制256字節)

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

if(payload && [[payload objectForKey:kContentAvailablePush] caseInsensitiveCompare:@“ 1”] == NSOrderedSame){NSLog(@“由於NS通知而推出”); }

您必須注冊報亭通知才能顯示在“設置”中並接收“報亭通知”。 要注冊,請將其添加到您的application:didFinishLaunchingWithOptions: ::

// Add registration for newsstand notifications
// In your application:didFinishLaunchingWithOptions:

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
  UIRemoteNotificationTypeNewsstandContentAvailability];

系統將要求用戶接受或不接受后台下載。

看看這個關於報亭應用程序的真正完整的教程: http : //www.viggiosoft.com/blog/blog/2011/10/17/ios-newsstand-tutorial/

確保在您的plist中設置了UINewsstandApp = YES

{"aps": {"badge": 1, "alert": "test","content-available":1}}這是正確的有效載荷。 {"aps": {"badge": 1, "alert": "test"},"content-available":1}這是錯誤的有效載荷。

當有效內容中有可用內容時,將發生以下情況:

  • 如果應用被暫停,系統會將其帶入后台
  • 如果應用被用戶殺死 ,則什么也不會發生,並且應用仍處於未運行狀態

基本上必須通過將警報消息添加到推式通知中來啟動用戶應用程序。

資源

http://samwize.com/2015/08/07/how-to-handle-remote-notification-with-background-mode-enabled/

但是,這不能解決您的問題。 解決方法是,您可以使用后台提取,每隔一定時間喚醒應用程序一次。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM