1

My push notifications sent from the Firebase console does not appear.. Yesterday, they appeared when i deleted my app, and freshly installed again - but only 1 time, and then they stopped appearing again. Today they dont appear at all..

I've tried to renew my APNs certificate, to create a new app on Firebase, to run the examplecode, check for correct bundle identifiers, check settings in xcode and now im lost for ideas..

I am able to receive push notifications from an APNs-tester, so I'm quite sure my certificate is good! It must be a Firebase problem somehow..

Here's my 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) {
}

}

I cant see whats missing - have anyone experienced the same problem, or know about a possible solution? :)

Best regards!

Nicolai Harbo
  • 1,064
  • 12
  • 25
  • send notification with high priority – Bhavin Bhadani Nov 18 '16 at 11:19
  • It is by standard in the Firebase console :-) So i'm afraid its not a solution :/ – Nicolai Harbo Nov 18 '16 at 11:23
  • Are you sending Message or Data Notification ? – CZ54 Nov 18 '16 at 12:41
  • @bobby: from the Firebase Notifications console, you can only send Notification messages – Frank van Puffelen Nov 18 '16 at 13:09
  • I use it and it works, but I did disable the swizzling. ( add a key in the plist, read the doc ) – CZ54 Nov 18 '16 at 13:34
  • Suddently it just worked.. I have no idea why - I didn't change the code at all, so I guess it was a problem on Firebase' server.. Also now, when I send http requests with notifications, i get InternalServerError 6 out of 10 times.. Really strange that it works on/off like that.. But thanks for the replies! Should I mark this as "solved" or whats the procedure? :) – Nicolai Harbo Nov 18 '16 at 16:19

0 Answers0