OneSignal / OneSignal-Flutter-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal
https://www.onesignal.com
Other
615 stars 213 forks source link

Conflict between OneSignal and Firebase Phone Auth #245

Closed rbresjer closed 3 years ago

rbresjer commented 4 years ago

Description:

I am working on a Flutter app which uses Firebase Phone Authentication. Firebase Phone Authentication works with silent remote notifications before sending a text message with an OTP, probably to prevent spammers from sending a lot of text messages. This worked fine.

Today I implemented OneSignal, which breaks Firebase Phone Authentication. Device tokens are not transferred to the Firebase library, nor are remote notifications. I assume this has to do with multiple libraries swizzling methods.

I tried disabling Firebase's method swizzling and implemented the Firebase callbacks myself in my own AppDelegate. Then Firebase works but OneSignal doesn't (got "Apns delegate never fired" in my OneSignal console). When I comment out the delegate methods in my AppDelegate, OneSignal works but Firebase doesn't.

The user is registered in OneSignal, with OS version and tags, but without push token and with the mentioned error. In-app notifications work (triggered with a tag, set up as described in the manual).

Environment

Steps to Reproduce Issue:

  1. Set up a Flutter project with a working Firebase Phone Authentication login
  2. Install the OneSignal Flutter SDK using pub into the project
  3. Initialize with OneSignal.shared.init([app_id]) and optionally some iOS parameters
  4. Try to log in with an actual phone number (not a test number)

Anything else:

jkasten2 commented 4 years ago

@rbresjer Thanks for all the details with version numbers!

Issue

This seems to point to Firebase swizzling in a way that is incompatible with OneSignal. Since you noted when you have your own AppDelegate methods + Firebase + OneSignal then your AppDelegate + Firebase works but OneSignal breaks. However this doesn't completely rule out OneSignal not handling something either.

Next Steps

The next steps is we will need to have a project with the minimal amount variables to narrow things down. A barebones example project reproducing the issue. Ideality a native Swift or Objective-c project but this may also be specific to Flutter. Once this is available with will greatly help Google or OneSignal pinpoint the issue if reproducible.

rbresjer commented 4 years ago

Hi @jkasten2, thank you for your reply.

As I'm implementing OneSignal for a client and I'm tied to a budget, I unfortunately don't have the time to setup an example project. We chose for OneSignal because it was supposed to be easy to setup, but due to this issue we are running way over budget...

Maybe this example project from a howto helps you to get going quickly: https://github.com/fayaz07/flutter_firebase (not sure if this works on iOS, they didn't test)

It would be really easy to fix this issue for me if OneSignal would allow disabling swizzling and to call the delegate methods manually.

jkasten2 commented 4 years ago

@rbresjer Thanks for links. Understandable about going over your integration time budget.

The issue seems to be related to Google's swizzling code based on the behavior however we will consider providing a way to disable swizzling in the future.

I do not have an ETA on either right now. But reproducing the issue will be the first step. We will update this ticket when we attempt this and report our results here.

droidluv commented 4 years ago

@jkasten2 is there any advice you can give? I need to migrate from Firebase PN to OneSignal and this issue is happening and a user who is registered is having "APNS delegate never fired" error happening to me, after adding the OneSignal SDK, Firebase phone auth starts throwing an error about method swizzling and I have to add the below code to my AppDelegate.swift

override func application(_ application: UIApplication,
                 didReceiveRemoteNotification notification: [AnyHashable : Any],
                 fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    if Auth.auth().canHandleNotification(notification) {
        completionHandler(.noData)
        return
    }
  }

and Firebase Phone Auth starts working and commenting out the above has OneSignal working basically the same issue as the OP where the delegate method is causing the issue and without which I cannot have have FirebaseAuth working.

Not sure what I can do to fix this issue, please advice!

chounry commented 4 years ago

@rgomezp do u have any solution yet.? Because my project will use both of these too.

ikarelin commented 4 years ago

I have the same issue also. When enabling a OneSignal SDK, I cannot login to Firebase with the phone. The error message: If app delegate swizzling is disabled, remote notifications received by UIApplicationDelegate need to be forwarded to FIRAuth's canHandleNotification: method

Youssef-Harby commented 4 years ago

I have the same issue with react native in ios Notification works but Firebase Auth is not ,, when i added pod 'Firebase/Auth' to pod file .. the Firebase Auth works and the OneSignal Notification not .

my package.json `

{ "name": " ", "version": " ", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint ." }, "dependencies": { "@invertase/react-native-apple-authentication": "^0.2.0", "@react-native-community/async-storage": "^1.8.1", "@react-native-community/google-signin": "^4.0.0", "@react-native-community/masked-view": "^0.1.7", "@react-native-community/netinfo": "^5.6.2", "@react-native-community/toolbar-android": "^0.1.0-rc.2", "@react-native-firebase/analytics": "^7.2.1", "@react-native-firebase/app": "^8.1.0", "@react-native-firebase/auth": "^8.1.1", "@react-native-firebase/crashlytics": "^8.1.1", "@react-native-firebase/dynamic-links": "^7.3.1", "@react-native-firebase/perf": "^7.2.1", "color": "^3.1.2", "currency-formatter": "^1.5.5", "deepmerge": "^4.2.2", "hoist-non-react-statics": "^3.3.2", "i18next": "17.0.16", "immutable": "^4.0.0-rc.12", "lodash": "^4.17.15", "moment": "^2.24.0", "moment-timezone": "^0.5.28", "password-validator": "^5.0.3", "query-string": "^6.11.1", "react": "16.13.1", "react-i18next": "^11.3.4", "react-native": "0.61.5", "react-native-confirmation-code-field": "5", "react-native-fbsdk": "^1.1.2", "react-native-file-viewer": "^2.0.2", "react-native-flash-message": "^0.1.15", "react-native-gesture-handler": "^1.6.1", "react-native-gifted-chat": "^0.13.0", "react-native-htmlview": "^0.15.0", "react-native-image-zoom-viewer": "^2.2.27", "react-native-onesignal": "^3.9.0", "react-native-phone-input": "https://github.com/rnlab/react-native-phone-input.git", "react-native-progress": "^4.1.2", "react-native-rate": "^1.1.10", "react-native-reanimated": "^1.7.1", "react-native-restart": "^0.0.13", "react-native-safe-area-context": "^0.7.3", "react-native-screens": "^2.4.0", "react-native-scrollable-tab-view": "^1.0.0", "react-native-snap-carousel": "^3.8.4", "react-native-splash-screen": "^3.2.0", "react-native-status-bar-height": "^2.5.0", "react-native-swipe-list-view": "^2.4.0", "react-native-swiper": "^1.5.14", "react-native-url-polyfill": "^1.1.2", "react-native-vector-icons": "^6.6.0", "react-native-video": "^5.0.2", "react-native-webview": "^9.0.1", "react-navigation": "^4.3.3", "react-navigation-drawer": "^2.4.7", "react-navigation-stack": "^2.3.6", "react-navigation-tabs": "^2.8.7", "react-redux": "^7.2.0", "recompose": "^0.30.0", "redux": "^4.0.5", "redux-persist": "^6.0.0", "redux-persist-transform-immutable": "^5.0.0", "redux-saga": "^1.1.3", "reselect": "^4.0.0", "rn-fetch-blob": "^0.12.0", "validator": "^13.0.0" }, "devDependencies": { "@babel/core": "^7.9.0", "@babel/runtime": "^7.9.2", "@react-native-community/eslint-config": "^0.0.7", "babel-jest": "^25.1.0", "babel-plugin-module-resolver": "^4.0.0", "eslint": "^6.8.0", "husky": "^4.2.3", "jest": "^25.1.0", "metro-react-native-babel-preset": "^0.59.0", "react-test-renderer": "16.13.1", "redux-devtools-extension": "^2.13.8" }, "jest": { "preset": "react-native" } }

`

my pod file `

platform :ios, '9.0' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

target 'OneSignalNotificationServiceExtension' do pod 'OneSignal', '>= 2.9.3', '< 3.0' end

target '*' do

Pods for *

pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector" pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec" pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired" pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety" pod 'React', :path => '../node_modules/react-native/' pod 'React-Core', :path => '../node_modules/react-native/' pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules' pod 'React-Core/DevSupport', :path => '../node_modules/react-native/' pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS' pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation' pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob' pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image' pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS' pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network' pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings' pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text' pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration' pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'

pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact' pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi' pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor' pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector' pod 'ReactCommon/jscallinvoker', :path => "../node_modules/react-native/ReactCommon" pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon" pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec' pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

pod 'FBSDKCoreKit', :modular_headers => true

target '*Tests' do inherit! :search_paths

Pods for testing

end

use_native_modules! end

target '*-tvOS' do

Pods for *-tvOS

target '*-tvOSTests' do inherit! :search_paths

Pods for testing

end

end

`

any one can help ?

alhassan233 commented 3 years ago

@droidluv were you able to find a solution? please help

djamel-madani-dev commented 3 years ago

Any solution for this ?

alhassan233 commented 3 years ago

What @droidluv shared worked for me. It wasn't working while i was in debug mode (installing from my pc to the device). But once i uploaded it to the app store and tried it from there, it worked

rgomezp commented 3 years ago

Since this was reported in multiple wrapper SDKs, we will consolidate the issue into the native iOS repository. Please continue discussion there.

Link

mrpawle commented 3 years ago

@rbresjer Did you resolve the issue? I'm facing the same issue.

rbresjer commented 3 years ago

@rbresjer Did you resolve the issue? I'm facing the same issue.

Nope, we decided not to use OneSignal. Shouldn't be too difficult for them to offer the option to disable swizzling, but apparently it is.