我最近在我的應用程序上設置了通知,我可以通過php發送,不用擔心,一切正常。通知iOs推送交付?
自上週以來,我試圖找出是否推送通知是由電話或沒有收到..
我可以知道,當有人點擊,但如果這個人不點擊它,喜歡打開應用程序,它不起作用..
是否沒有一個簡單的函數可以告訴我,如果通知剛剛收到應用程序?
在我AppDelegate.swift:
import UIKit
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Check if launched from notification
if let notification = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] as? [String: AnyObject] {
//print(notification)
window?.rootViewController?.present(ViewController(), animated: true, completion: nil)
}
else{
//print("ici ?")
registerForRemoteNotification()
}
return true
}
...
//Called when a notification is delivered to a foreground app.
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .badge, .sound])
}
//Called to let your app know which action was selected by the user for a given notification.
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping() -> Void) {
completionHandler()
}
...
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
**print("here ?")**
switch((application.applicationState)){
case UIApplicationState.inactive:
print("Inactive")
//Show the view with the content of the push
completionHandler(.newData)
case UIApplicationState.background:
print("Background")
//Refresh the local model
completionHandler(.newData)
default:
print("Active")
//Show an in-app banner
completionHandler(.newData)
break
}
}
}
問題:我從來沒有在didReceiveRemoteNotification通過:/ 「打印這裏」 永遠不會顯示。
我在這一行錯誤:
Instance method 'application(application:didReceiveRemoteNotification:fetchCompletionHandler:)' nearly matches optional requirement 'application(_:didReceiveRemoteNotification:fetchCompletionHandler:)' of protocol 'UIApplicationDelegate'
但我不明白:/
你有一個想法?
THX對您有所幫助^^
無論你在你的第三解釋說,只有我們可以檢查用戶輕按通知。當用戶刷卡通知無法檢查時,此功能在蘋果文檔中不可用。 – Pavankumar
無法檢查我的應用是否收到推送? O_o – Insou
http://stackoverflow.com/questions/25830597/how-to-know-push-notification-delivery-status,去與鏈接,我研究也沒有保證說的交付與否。在我們的應用程序中,我們也嘗試了這一個,那時我才知道不可能,只有當用戶點擊那個時候纔可能。 – Pavankumar