Thursday, August 11, 2022
HomeiOS Developmentios - Flutter - Firebase_messaging migrating from v7 to v11

ios – Flutter – Firebase_messaging migrating from v7 to v11


I would like some assist in migrating my mission.
Mainly mission is a bit outdated now, its operating for nearly 3 years and till now it was constructed with flutter 1.22.6. Now i’m attempting emigrate it to v2.10.3 and migration is sort of achieved. Final not working piece is iOS Push Notifications.

Outdated model is operating on firebase_messaging v.7.0.3 and it is working simply wonderful.
Upgrading flutter calls for model 9.0.0 or larger.

I’ve achieved primary code migration and Android is OK, however on iOS my onMessage handler is rarely being referred to as.
Push is being delivered and notification is being displayed appropriately when app is in background. However when its in foreground, or i’ll click on that notification, app comes into the foreground, however callbacks are usually not being triggered.

The one factor i see in logs is error like:
nw_endpoint_handler_set_adaptive_read_handler [C6.1 216.58.212.42:443 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, dns)] unregister notification for read_timeout failed

OFC i’ve regarded by way of most of subjects on stack and different locations, however none of those options labored for me.
I am not utilizing every other plugins, corresponding to flutter_local_notifications or related, which might trigger faults.

Most vital items of code:

flutter physician

Physician abstract (to see all particulars, run flutter physician -v):
[✓] Flutter (Channel unknown, 2.10.3, on macOS 11.6 20G165 darwin-x64, locale
    pl-PL)
[✓] Android toolchain - develop for Android units (Android SDK model
    33.0.0-rc3)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2)
[✓] Chrome - develop for the online
[✓] Android Studio (model 4.2)
[✓] VS Code (model 1.67.1)
[✓] Related machine (1 accessible)
[✓] HTTP Host Availability

pubspec.yaml

  firebase_core: 1.16.0
  firebase_messaging: 11.3.0
  google_ml_kit: 0.7.3

AppDelegate.swift

override func software(
        _ software: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
    ) -> Bool {
        disableCache();
        FirebaseConfiguration.shared.setLoggerLevel(.min)
        FirebaseApp.configure()
        self.SetupPushNotification(software: software)
    
    func SetupPushNotification(software: UIApplication) -> () {
        if #accessible(iOS 10, *){ UNUserNotificationCenter.present().requestAuthorization(choices: [.alert,.sound,.badge])
        {(granted,error) in
            if granted{
                DispatchQueue.primary.async {
                    software.registerForRemoteNotifications()
                }
            } else {
                print("Person Notification permission denied: (error?.localizedDescription ?? "error")")
            }
        }
        }
    }
    
    override func software(_ software: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Knowledge) {
        NotificationDeviceToken.sharedInstance.setToken(token: tokenString(deviceToken))
     }

    override func software(_ software: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
        print("Did not register for distant notifications: (error.localizedDescription)")
    }
    
    override func software(_ software: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
        print(userInfo)
     }

     func tokenString(_ deviceToken:Knowledge) -> String{
         let bytes = [UInt8](deviceToken)
         var token = ""
         for byte in bytes{
             token += String(format: "%02x",byte)
         }
         return token 
     }

primary.dart

void startApp(AppConfig config) async {
  // add this, and it must be the primary line in primary methodology
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  ...
}

app.dart

  void init(BuildContext context, AppCubit cubit,
      SubscriptionManager subscriptionManager) {
    await FirebaseMessaging.occasion.getToken();
    FirebaseMessaging.onMessage.hear((map) {
      _log.debug('onMessage: ${map.knowledge}');
      closing push = Push(map.knowledge, PushType.onMessage);
      _streamController.add(push);
      return Future<bool>.worth(true);
    });

    FirebaseMessaging.onMessageOpenedApp.hear((map) {
      _log.debug('onMessageOpenedApp: ${map.knowledge}');
      _startAppFromPush = true;
      closing push = Push(map.knowledge, PushType.onLaunch);
      _streamController.add(push);
      return Future<bool>.worth(true);
    });
  }

Data.plist

...
<key>FirebaseAppDelegateProxyEnabled<key/>
<false/>
...

Any assist can be appreciated.
Thanks upfront.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments