[英]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 )];
我還看到我的應用程序未顯示在“設置”->“商店”->“自動下載”下(其他雜志出現在此處)。
我想念什么嗎? 這應該在沙盒環境中工作嗎?
一些澄清
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.