Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

await Pushy.register hangs #20

Closed
grantespo opened this issue Dec 4, 2020 · 1 comment
Closed

await Pushy.register hangs #20

grantespo opened this issue Dec 4, 2020 · 1 comment

Comments

@grantespo
Copy link

grantespo commented Dec 4, 2020

I am using the latest version pushy_flutter: 1.1.7

I am following the docs. Pushy.listen() and Pushy.setNotificationListener(backgroundNotificationListener); seem to work okay, however Pushy.register() hangs.

try {
      print("pushyRegister try{}");
      String deviceToken = await Pushy.register();
      print("pushyRegister deviceToken " + deviceToken);
    } catch (error) {
      print("pushyRegister catch " + error);
    }

In my logcat, I only see "pushyRegister try{}".
catch isn't being called. Any ideas of why this could happen.

I am also using Firebase in my project

@pushy
Copy link
Owner

pushy commented Dec 4, 2020

Hi @grantespo,
Thanks for reporting this issue.

We've now added an option to make it possible to use Firebase & Pushy together in the same iOS project.

  1. Please edit the pubspec.yaml in the root directory of your project and update the plugin version referenced to the following:
pushy_flutter: 1.1.8

Run flutter pub get.

  1. Add the following line of code in your project's lib/main.dart right after Pushy.listen():
// Disable Pushy AppDelegate method swizzling
Pushy.toggleMethodSwizzling(false);
  1. Disable Firebase SDK method swizzling by adding the FirebaseAppDelegateProxyEnabled flag to your project's Info.plist file and setting it to NO (boolean value). More info: https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in.

  2. Edit your ios/Runner/AppDelegate.swift, adding the following import line and overriding methods:

import Pushy

// APNs has assigned the device a unique token
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    // Call internal Pushy SDK method
    Pushy.shared?.application(application, didRegisterForRemoteNotificationsWithDeviceToken:deviceToken)

    // Pass token to Firebase SDK
    Messaging.messaging().apnsToken = deviceToken
}

// APNs failed to register the device for push notifications
override func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    // Call internal Pushy SDK method
    Pushy.shared?.application(application, didFailToRegisterForRemoteNotificationsWithError:error)
}

// Device received notification (legacy callback)
override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
    // Call internal Pushy SDK method
    Pushy.shared?.application(application, didReceiveRemoteNotification:userInfo)

    // With swizzling disabled you must let Messaging know about the message, for Analytics
    Messaging.messaging().appDidReceiveMessage(userInfo)
}

// Device received notification (with completion handler)
override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    // Call internal Pushy SDK method
    Pushy.shared?.application(application, didReceiveRemoteNotification:userInfo, fetchCompletionHandler: completionHandler)

    // With swizzling disabled you must let Messaging know about the message, for Analytics
    Messaging.messaging().appDidReceiveMessage(userInfo)
}
  1. Run your app and observe whether both the Pushy SDK and Firebase are able to register successfully and receive notifications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants