我想執行接收推送通知的任務。我用- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
方法編寫了我的代碼。當應用程序處於前臺時它工作正常,但當應用程序在後臺時,上述方法沒有被調用。有什麼辦法可以在應用程序處於後臺時調用此方法。這個程序是不是提交給iTunes,所以任何好hack詭計? ;)在接收推送通知後執行任務
0
A
回答
0
每當應用程序進入後臺時,所有通知都會在backgound線程中發生。所以你需要做這樣的事情。
...
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(processNotificationInBackground:)
name:TheNameOfTheNotification
object:nil];
...
- (void) processNotificationInBackground:(NSNotification *)not {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
/* your background notification processing code goes here */
/* note that you should transfer control back to the main queue if you need to update your UI */
}
}
+0
它不適用於我:( –
+0
你跟蹤是否生成通知並觀察選擇器被調用嗎? –
+0
是的,這裏選擇器沒有被調用,我測試了它[「[[NSNotificationCenter defaultCenter] postNotificationName:TheNameOfTheNotification對象:自己];「 –
相關問題
- 1. 當接收到推送通知時,在後臺執行代碼
- 2. WP8.1接收推送通知
- 3. iOS後臺任務/推送通知
- 4. 在接收推送通知時在後臺運行javascript函數?
- 5. 推送通知執行
- 6. 推送通知不在iphone上接收
- 7. 我在IOS上沒有在後臺接收fcm推送通知
- 8. 在onMessage()上收到推送通知時執行一些代碼
- 9. 使用Node.js接收推送通知webToolkit
- 10. AdHoc構建不接收推送通知
- 11. 接收推送通知從Sinch,Swift 3
- 12. 推送通知iOS 8未接收
- 13. 顯示接收的推送通知
- 14. Iphone無法接收推送通知
- 15. 用聲音接收推送通知
- 16. 接收推送通知不一致
- 17. Android parse.com無法接收推送通知
- 18. Xtify - 未接收推送通知 - Android
- 19. 應用程序崩潰在後臺接收推送通知
- 20. 推送通知不在後臺接收iOS
- 21. 當在後臺的應用程序接收pushwoosh推送通知
- 22. 在後臺顯示整個接收內容的推送通知
- 23. 在Window Phone 8.1從服務器接收到原始推送通知後執行某些功能
- 24. 未收到推送通知
- 25. 未收到推送通知
- 26. Can Ionic能否接收推送通知而沒有推送服務?
- 27. didRegisterForRemoteNotificationsWithDeviceToken不執行 - 推送通知
- 28. 執行iOS推送通知的問題
- 29. 在推送通知後打開應用時執行操作?
- 30. 在後臺執行響應推送通知 - ios
請更新我,如果這工作或沒有。 –