2016-12-07 11 views
0

私は最近、アプリケーションで通知を設定しました。私は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

、唯一の我々は、通知をタップし、ユーザーを確認することができます。ユーザーが通知をスヌープすると、この機能はAppleのドキュメントでは利用できません。 – Pavankumar

+0

私のアプリがプッシュを受け取るかどうかを確認することはできませんか? O_o – Insou

+0

http://stackoverflow.com/questions/25830597/how-to-know-push-notification-delivery-status、リンクを参照してくださいと私はまた、配信されたかどうかを言う保証を勉強した。私たちのアプリでも、私たちはこの1つを試してみました。 – Pavankumar

答えて

1

それはスウィフト3への転換以来、むしろ一般的な間違いだ - あなたはスウィフト2の方法を使用しています。

スウィフト3で、この方法の権利署名がある:あなたがあなたの第三の説明で述べたものは何でも

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

ああ、それは私のコードに...ちょうど悪いコピー/ペーストだ、それはスウィフト3のために、右の署名だ私の悪い^^ しかし、それはまだ動作しませんです:/ – Insou

+0

あなたはiOS 10でそれを実行していますか? – Elena

+0

はい、iOS 10で.. – Insou

関連する問題