firebase-ios-sdk icon indicating copy to clipboard operation
firebase-ios-sdk copied to clipboard

Push Notification does not receive on my some devices

Open shihochan opened this issue 9 years ago • 10 comments

I have the problem don't receive push notification on my some devices by Firebase Console.

Environment:

  • Xcode9
  • Swift4
  • Send messages with Firebase Console
    • with selected my app bundle in user segment

Devices:

  • iPhone6S Plus (9.3.2)
  • iPhone5S (10.3.2)
  • iPad Pro (10.2.1)
  • iPhone7 Plus (10.2.1)

My Podfile.lock:

  - Firebase/Core (4.3.0):
  - Firebase/Messaging (4.3.0):
    - FirebaseMessaging (= 2.0.4)
  - FirebaseInstanceID (2.0.4)

My codes:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        
        // For push
       let application = UIApplication.shared
        
        if #available(iOS 10, *) {
            UNUserNotificationCenter.current().delegate = self
            
            UNUserNotificationCenter.current()
                .requestAuthorization(options: [.alert, .badge, .sound]) { _, _ in }
        } else {
            let settings = UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
            application.registerUserNotificationSettings(settings)
        }
        
        application.registerForRemoteNotifications()

        if #available(iOS 10, *) {
            // do nothing
        } else {
            if let userInfo = launchOptions?[.remoteNotification] as? [AnyHashable: Any] {
                Log("userInfo: \(userInfo)")        
            }
        }
        
        return true
    }

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        Messaging.messaging().apnsToken = deviceToken
    }
    
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
        Log("userInfo: \(userInfo)")        
    }
}

@available(iOS 10.0, *)
extension AppDelegate: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        let userInfo = notification.request.content.userInfo
        Log("userInfo: \(userInfo)")
        
        completionHandler([.alert, .sound])
    }
    
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler: @escaping () -> Void) {
        let userInfo = response.notification.request.content.userInfo
        Log("userInfo: \(userInfo)")
        
        completionHandler()
    }
}

Did v2.0.4~ really fix push problem??

shihochan avatar Oct 20 '17 11:10 shihochan

The fix in 2.0.4 wasn't related to user segments. If you're able to send to most other devices and only a few aren't working, then it most likely means your FCM and APNs setups are correct.

Have you ever used multiple bundle IDs for this one project (for example one for dev and one for prod)? Does deleting the app on the problem devices, reinstalling, and relaunching change anything?

morganchen12 avatar Oct 20 '17 18:10 morganchen12

@morganchen12 Thank you for your information.

Have you ever used multiple bundle IDs for this one project (for example one for dev and one for prod)? Does deleting the app on the problem devices, reinstalling, and relaunching change anything?

yes, I used multiple bundle IDs for this one project. deleted the app on the problem devices, reinstalling, and relaunching, then it worked. I noticed to send push notification for other bundle ID when installed many apps multiple bundle IDs for one project.

shihochan avatar Oct 21 '17 09:10 shihochan

I don't quite understand the last sentence. Are there issues when sending to user segments with multiple versions of the same app installed with different bundle IDs?

morganchen12 avatar Oct 23 '17 17:10 morganchen12

I had a similar problem receiving push notifications (in 4.2.0) and I fixed it updating to 4.4.0 version.

This are my current SDK versions:

Firebase | 4.4.0 FirebaseInstanceID | 2.0.5 FirebaseMessaging | 2.0.5

jcarlosestela avatar Oct 24 '17 15:10 jcarlosestela

@shihochan closing this issue since it seems to be resolved. Please re-open if you still have trouble.

morganchen12 avatar Oct 24 '17 17:10 morganchen12

@morganchen12 I'm Sorry. This was only our development environment problem. We are switching GoogleService-Info.plist for each environment using script. This script had bug to use other environment plist.

shihochan avatar Oct 25 '17 04:10 shihochan

@morganchen12 I've experiencing some issue with FCM lately. Same device, sometimes the notification comes in, sometimes it doesn't. FCM API returns success message. Also, I noticed that the notification token gets refreshed quite frequently (every 2-3 days). If notification token expires, would FCM API returns success ? Also, how often should notification token gets refreshed?

richardliveraise avatar Jul 13 '18 22:07 richardliveraise

@richardliveraise in the future please file a new issue. If you have further questions, please file them as a new issue instead of commenting more here.

  • Can you share particulars on how your notifications are delivered and how token refresh is handled? Relatively frequent token refresh is normal and not likely to be a source of bugs, but your client needs to make sure it's handling token refresh appropriately.
  • On notification expiration Instance ID will normally generate a new token, so FCM sends won't fail.
  • I'm not sure how often tokens are refreshed (@chliangGoogle may know).

morganchen12 avatar Jul 16 '18 19:07 morganchen12

@morganchen12 @richardliveraise I have also facing same issue. do you get any clue or any solution? after reinstalling app one are getting FCM push notifications. https://stackoverflow.com/questions/55793302/ios-12-fcm-push-notification-not-received guys any solution?

ankur62 avatar Apr 22 '19 12:04 ankur62

@richardliveraise This might be the same issue as #2438. Can you try to patch the change https://github.com/firebase/firebase-ios-sdk/pull/2860 and see if it resolves the issue?

charlotteliang avatar Apr 22 '19 20:04 charlotteliang