1

Firebase コンソールから送信されたプッシュ通知が表示されません。今日、彼らはまったく現れません..

APNs 証明書を更新し、Firebase で新しいアプリを作成し、examplecode を実行し、正しいバンドル識別子を確認し、xcode で設定を確認しようとしましたが、今はアイデアがありません..

APNs-tester からプッシュ通知を受け取ることができるので、証明書が良好であることは間違いありません! どういうわけかFirebaseの問題に違いない..

これが私のappDelegateです:

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    UIApplication.sharedApplication().statusBarStyle = .Default
    // Parse
    User.initialize()
    PFCategory.initialize()
    Follow.initialize()
    Activity.initialize()
    PostElement.initialize()
    PFComment.initialize()
    Socials.initialize()
    Notification.initialize()

    let configuration = ParseClientConfiguration {
        $0.applicationId = "Agpq2y3O2Gxxxxxx"
        $0.clientKey = "k2bM8XTYf354fxAxxxxxxxxxx"
        $0.server = "https://parseapi.back4app.com/"
        $0.localDatastoreEnabled = false
    }
    Parse.initializeWithConfiguration(configuration)
    PFFacebookUtils.initializeFacebookWithApplicationLaunchOptions(launchOptions)

    // Firebase configuration
    FIRApp.configure()

    // Facebook
    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

    // Add observer for InstanceID token refresh callback.
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.tokenRefreshNotification), name: kFIRInstanceIDTokenRefreshNotification, object: nil)

    //Register for remote notifications
    let notificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
    let pushNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
    application.registerUserNotificationSettings(pushNotificationSettings)
    application.registerForRemoteNotifications()

    return true
}

// When app registered for remote notification
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {

    print("** DEVICE TOKEN = \(deviceToken) **")

    FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: FIRInstanceIDAPNSTokenType.Unknown)
    print("** APNS Token set!! **")
}

// When app failed to register for remote notification
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
    // Print the error, if failing to register for push notifications
    print("AppDelegate, failed with registering for remote notifications: \(error)")
}

// If no token, or token has changed, this method is called to refresh it!
func tokenRefreshNotification(notification: Notification) {
    if let refreshedToken = FIRInstanceID.instanceID().token() {
        print("InstanceID token: \(refreshedToken)")

    }

    // Connect to FCM since connection may have failed when attempted before having a token.
    connectToFcm()
}

func connectToFcm() {
    FIRMessaging.messaging().connectWithCompletion { (error) in
        if error != nil {
            print("Unable to connect with FCM. \(error)")
        } else {
            print("Connected to FCM.")
        }
    }
}

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
    print("didRegisterUserNotificationSettings")
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject: AnyObject]) {
    // Let FCM know about the message for analytics etc.
    FIRMessaging.messaging().appDidReceiveMessage(userInfo)

    // If you are receiving a notification message while your app is in the background,
    // this callback will not be fired till the user taps on the notification launching the application.
    // TODO: Handle data of notification

    // Print message ID.
    print("Message ID: \(userInfo["gcm.message_id"]!)")

    // Print full message.
    print(userInfo)
}

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
    // Let FCM know about the message for analytics etc.
    FIRMessaging.messaging().appDidReceiveMessage(userInfo)

    // If you are receiving a notification message while your app is in the background,
    // this callback will not be fired till the user taps on the notification launching the application.
    // TODO: Handle data of notification

    // Print message ID.
    print("Message ID: \(userInfo["gcm.message_id"]!)")

    // Print full message.
    print(userInfo)
}

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    return PDKClient.sharedInstance().handleCallbackURL(url) || FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}

func applicationWillResignActive(application: UIApplication) {
}

func applicationDidEnterBackground(application: UIApplication) {
    print("------APP IN BACKGROUND!!!!!------")
    // Setting the user to offline in Parse - be aware of bad connection, this may fuck it up
    api.setOnlineStatus("offline")

    // Setting the batchnumber to 0 and disconnecting from FCM
    application.applicationIconBadgeNumber = 0;
    FIRMessaging.messaging().disconnect()
    print("Disconnected from FCM.")
}

func applicationWillEnterForeground(application: UIApplication) {
}

func applicationDidBecomeActive(application: UIApplication) {
    print("------APP DID BECOME ACTIVE!!!!!------")
    firebase = FirebaseManager()
    connectToFcm()
    FBSDKAppEvents.activateApp()
}

func applicationWillTerminate(application: UIApplication) {
}

}

何が欠けているのかわかりません。同じ問題を経験した人、または可能な解決策について知っている人はいますか? :)

よろしくお願いします!

4

0 に答える 0