通知iOs推送交付?

问题描述:

我最近在我的应用程序上设置了通知,我可以通过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对您有所帮助^^

+0

无论你在你的第三解释说,只有我们可以检查用户轻按通知。当用户刷卡通知无法检查时,此功能在苹果文档中不可用。 – Pavankumar

+0

无法检查我的应用是否收到推送? O_o – Insou

+0

http://stackoverflow.com/questions/25830597/how-to-know-push-notification-delivery-status,去与链接,我研究也没有保证说的交付与否。在我们的应用程序中,我们也尝试了这一个,那时我才知道不可能,只有当用户点击那个时候才可能。 – Pavankumar

这是因为转换到斯威夫特3,而常见的错误 - 你用斯威夫特2方法。

在斯威夫特3这种方法的正确的签名是:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) { 
    print("here?") 
} 
+0

哦,它只是一个糟糕的复制/粘贴......在我的代码,这是正确的签名,为雨燕3 .. 我的坏^^ 但它仍然不工作:/ – Insou

+0

你在iOS 10中运行它吗? – Elena

+0

是的,在iOs 10 .. – Insou