-1
A
回答
1
我使用本地通知,所以我會給你一個關於我做什麼的例子。我不知道它是否與推送通知相同。
我做的是設置的appdelegate以符合用戶通知委託
1:導入
import UserNotifications
2:添加協議
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate
3:通知中心實例
var notificationCenter: UNUserNotificationCenter!
4:初始化並設置委託
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
notificationCenter = UNUserNotificationCenter.current()
notificationCenter.delegate = self
return true
}
5:通知中心響應
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) {
print("notification pressed")
}
+0
你可以做同樣的事情(添加noti中心委託)在一個分離的類,但你需要保持它在appDelegate中實例化。希望能幫助到你! –
+0
很有貢獻,很詳細!但必須說,這隻適用於iOS 10或更高版本。 –
+0
Ohhh yes yes對不起:( –
相關問題
- 1. 當應用程序打開時,推送通知不起作用
- 2. 當應用程序打開時停止推送通知振動
- 3. Trigger.IO:知道什麼時候通過推送通知打開應用程序
- 4. 每當我打開我的應用程序時,推送通知不斷出現
- 5. 解鎖iPad時,推送通知提醒打開應用程序
- 6. 推送通知提醒打開iPhone時解鎖應用程序
- 7. 推送通知時,打開應用程序
- 8. 如何檢測應用程序打開時的推送通知
- 9. 用戶通過觸摸收到的推送通知打開應用程序
- 10. 通過推送通知啓動調試應用程序
- 11. 通知Android:當應用程序打開時不顯示通知?
- 12. 通過推送通知打開spicific ViewController
- 13. 響應推送通知,而無需打開應用程序
- 14. 當在Ionic 2中打開應用程序時處理推送通知
- 15. 當應用程序打開時未收到Android上的推送通知
- 16. 檢測是否通過推送通知打開了React Native iOS應用程序
- 17. 如何關閉當前打開的應用程序,當點擊推送通知
- 18. 每當應用程序在Android中打開時都會發送通知
- 19. iOS推送通知打開不同的應用程序
- 20. 檢查應用程序是否從推送通知中打開
- 21. 在收到推送通知後打開應用程序
- 22. 本地通知被推送,但應用程序無法打開
- 23. 使應用程序不能打開推送通知點擊
- 24. 如何停止推送通知自動打開應用程序?
- 25. 打開推送通知後的應用程序崩潰
- 26. 當收到推送通知時自動打開供應商應用程序(自動'按'通知)
- 27. android - 從推送通知中打開應用程序掛起應用程序
- 28. 當應用程序關閉目標時,我的應用程序從推送通知中打開時檢測到。
- 29. 通過Parse推送通知:當應用程序在後臺時顯示提醒
- 30. 推送通知每次在應用程序啓動時顯示
你嘗試用** ** applicationWillEnterForeground或 ** ** applicationDidBecomeActive ? –
但我怎麼才能區分,如果應用程序是手動打開或通過推送通知點擊?如果推送有效,我需要在我的儀表板中看到它。 –
「通過推送通知點擊」是什麼意思?請用 –