0

私は、私のアプリケーションのプッシュ通知を実装しました。すべての証明書をソートして、すべてがXcode内で実行されている必要があります。 .p12ファイルを開発セクションのFirebaseにアップロードし、プロビジョニングプロファイルをダウンロードしてプロジェクトに再インストールしました。通知がFirebaseで表示されない

import UIKit 
import Firebase 
import FirebaseMessaging 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 
    var storyboard: UIStoryboard? 

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
     FIRApp.configure() 

     // Override point for customization after application launch. 

     self.storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()) 
     let currentUser = FIRAuth.auth()?.currentUser 
     if currentUser != nil 
     { 
      self.window?.rootViewController = self.storyboard?.instantiateViewControllerWithIdentifier("tBVC") 
     } 
     else 
     { 
      self.window?.rootViewController = self.storyboard?.instantiateViewControllerWithIdentifier("loginScreen") 
     } 

     return true 
    } 

    func registerForPushNotifications(application: UIApplication) { 
     let notificationSettings = UIUserNotificationSettings(
      forTypes: [.Badge, .Sound, .Alert], categories: nil) 
     application.registerUserNotificationSettings(notificationSettings) 
    } 

    func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) { 
     if notificationSettings.types != .None { 
      application.registerForRemoteNotifications() 
     } 
    } 

    func applicationWillResignActive(application: UIApplication) { 
     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
     // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 
    } 

    func applicationDidEnterBackground(application: UIApplication) { 
     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
    } 

    func applicationWillEnterForeground(application: UIApplication) { 
     // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 
    } 

    func applicationDidBecomeActive(application: UIApplication) { 
     // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
    } 

    func applicationWillTerminate(application: UIApplication) { 
     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
    } 

    func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 

     print(userInfo) 
     print("MessageID: \(userInfo["gcm_message_id"]!)") 
     // 
    } 


} 

アプリがバックグラウンドで何の通知表示を実行されていない、私のデバイスは何もまだロックされていなくても:

この

は私 AppDelegate.swiftファイルに

更新されたコードのコードです。アプリが通知を送信する許可を持っているかどうかを尋ねる警告が表示され、はいと答えた。

私はtutorial

私の通知が表示されていない理由を任意のアイデアを、これを続きますか? Firebaseコンソールで それは通知のステータスが

EDIT「完了」していることを述べている - Xcodeのenter image description here

+0

スウィズルを無効にしましたか? –

+0

申し訳ありません正確には – Konsy

+0

AppleのアプリのインスタンスIDトークンとアプリのAPNトークンを自動的に関連付けたコードです。これがデフォルトでオンになっているため、これは問題になることはまずありません。 –

答えて

1

私はなぜそうしたのかの理由を調べました! @Collinizerは、AppleとAPNSには問題があると述べているが、現在はすべて動作している!私はOneSignalを使用してプッシュ通知を追加し、彼らは夢のように働いています!

ありがとうございました。

0

を私の能力の画像を追加しましたあなたがあるAPNSデバイストークンのセットアップ、設定する必要がありますがFirebase Cloud Messaging(FCM)で通知をプッシュするために重要です。

まず最初に少しバックアップし、少なくともトークンの成功を得ることができるかどうかを見てみましょう。

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 

FIRApp.configure() 
return true 
} 

func registerForPushNotifications(application: UIApplication) { 
    let notificationSettings = UIUserNotificationSettings(
     forTypes: [.Badge, .Sound, .Alert], categories: nil) 
    application.registerUserNotificationSettings(notificationSettings) 
} 

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) { 
    if notificationSettings.types != .None { 
     application.registerForRemoteNotifications() 
    } 
} 


func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) { 
let tokenChars = UnsafePointer<CChar>(deviceToken.bytes) 
var tokenString = "" 

for i in 0..<deviceToken.length { 
    tokenString += String(format: "%02.2hhx", arguments: [tokenChars[i]]) 
} 


FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Unknown) 
print("Device Token:", tokenString) 
} 
+0

大変感謝しています! btw – Konsy

+0

を完了し、Bundle IDがGoogleService-Infoで設定したものと同じであることを確認してください。これらが正しく、一致していることを確認してください:http://i.stack.imgur.com/p5N2F.png。目標は最初にトークンをテストすることです。 – tymac

+0

ええ、それはすべて証明書に関して正しく設定されており、私のfirebaseダッシュボードの設定は正しいです。私のプロジェクト全体はちょうど本当に古い(最初のバージョン)に戻りました。私がちょうどそれが保存されていても新しい仕事のすべてを失ったということを意味します... – Konsy

関連する問題