pubnub / dart

PubNub Dart SDK
Other
27 stars 15 forks source link

Invalid device token #23

Closed nimda1902 closed 3 years ago

nimda1902 commented 3 years ago

Hi ,

i got error when try to add push channel on IOS simulator.

`PubNubException: null error: Invalid device token

0 new PubNubException (package:pubnub/src/core/exceptions.dart:9:29)

  #1      getExceptionFromDefaultResult (package:pubnub/src/dx/_utils/exceptions.dart:37:10)
  #2      getExceptionFromAny (package:pubnub/src/dx/_utils/exceptions.dart:7:12)
  #3      _defaultFlow (package:pubnub/src/dx/_utils/default_flow.dart:52:11)
  <asynchronous suspension>
  #4      defaultFlow.<anonymous closure> (package:pubnub/src/dx/_utils/default_flow.dart:15:21)
  #5      Fiber.run (package:pubnub/src/core/supervisor/fiber.dart:34:32)
  #6      defaultFlow (package:pubnub/src/dx/_utils/default_flow.dart:21:15)
  #7      PushNotificationDx.addPushChannels (package:pubnub/src/dx/push/push.dart:71:12)
  #8      FcmUtil.init (package:mychat_app/shared/common/fcm_util.dart:100:12)
  <asynchronous suspension>
  #9      _InitializeApplicationState.initLocalStorage.<anonymous closure>.<anonymous closure> (package:mychat_app/app_init.dart:67:19)
  <asynchronous suspension>
  #10     _InitializeApplicationState.initLocalStorage.<anonymous closure>.<anonymous closure> (package:mychat_app/app_init.dart)
  #11     _rootRunUnary (dart:async/zone.dart:1198:47)
  #12     _CustomZone.runUnary (dart:async/zone.dart:1100:19)
  #13     _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
  #14     Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
  #15     Future._propagateToListeners (dart:async/future_impl.dart:725:32)
  #16     Future._completeWithValue (dart:async/future_impl.dart:529:5)
  #17     _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15)
  #18     _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13)
  #19     Service.request (package:mychat_app/shared/db/service/service.dart)
  <asynchronous suspension>
  #20     _InitializeApplicationState.initLocalStorage.<anonymous closure> (package:mychat_app/app_init.dart:57:14)
  <asynchronous suspension>
  #21     _InitializeApplicationState.initLocalStorage.<anonymous closure> (package:mychat_app/app_init.dart)
  #22     new Future.delayed.<anonymous closure> (dart:async/future.dart:326:39)
  #23     _rootRun (dart:async/zone.dart:1182:47)
  #24     _CustomZone.run (dart:async/zone.dart:1093:19)
  #25     _CustomZone.runGuarded (dart:async/zone.dart:997:7)
  #26     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
  #27     _rootRun (dart:async/zone.dart:1190:13)
  #28     _CustomZone.run (dart:async/zone.dart:1093:19)
  #29     _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1021:23)
  #30     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
  #31     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:397:19)
  #32     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5)
  #33     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)`

my code

await pubnubApp.pubnub .addPushChannels( await _firebaseMessaging.getToken(), Platform.isIOS ? pn.PushGateway.apns2 : pn.PushGateway.gcm, channels, environment: AppConfig.appMode == 'devel' ? pn.Environment.development : pn.Environment.production, topic: 'mytopic')

flutter doctor -v

`[✓] Flutter (Channel stable, 1.22.2, on Mac OS X 10.15.7 19H2, locale en-GB) • Flutter version 1.22.2 at /opt/flutter • Framework revision 84f3d28555 (25 hours ago), 2020-10-15 16:26:19 -0700 • Engine revision b8752bbfff • Dart version 2.10.2

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2) • Android SDK at /Users/md.nurfikri/Library/Android/sdk • Platform android-30, build-tools 29.0.2 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405) • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.0.1, Build version 12A7300 • CocoaPods version 1.9.3

[✓] Android Studio (version 3.5) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin version 44.0.1 • Dart plugin version 191.8593 • Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)

[✓] IntelliJ IDEA Community Edition (version 2020.1.4) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 48.1.3 • Dart plugin version 201.9002

[✓] VS Code (version 1.50.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.15.1

[✓] Connected device (2 available) • Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 10 (API 29) (emulator) • iPhone 11 Pro Max (mobile) • 8700980D-5E58-4DC4-BD02-CC06CA7FA3DE • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-0 (simulator)

• No issues found!`

mohitpubnub commented 3 years ago

Hi, Thanks for providing information to look into the problem you have faced.

In exception details Invalid device token is from server. Specially in case of apns2: If token(/deviceId) is of invalid length then server throws error with message Expected 32 or 100 byte hex device token but since you are receiving message of invalid token- It should be issue of invalid characters in deviceId. So I would request you to verify once that deviceId is correct/ the same which you intended to pass when the condition meets for PusGateway apns2 type.

nimda1902 commented 3 years ago

the token is from firebaseMessaging.getToken(), how could i verify it?

mohitpubnub commented 3 years ago

Seems like It's fcm/gcm token and with ios simulator the method call is happening with PushGateway.apns2argument so for apns2 type, the token is invalid.

parfeon commented 3 years ago

@mohitpubnub it is possible embed Firebase into iOS application and use it's own tokens with Firebase console. It looks like, under the hood Firebase SDK does exchange of actual device token (the one, which usually iOS application use) on Firebase token (which looks similar to the one, which you will get on Android).

@nimda1902 is it possible to show at leats portion of output from firebaseMessaging.getToken()?

parfeon commented 3 years ago

But @mohitpubnub is correct, if there will be FCM-like token (for me it looks like JWT), then you will need to use other type during registration (for FCM).

nimda1902 commented 3 years ago

@parfeon , yes it's JWT. fB1ukAscToCON1IJU_vs3X:APA91bF0dJU....
Already change to DeviceInfoPlugin to get unique id, but still got same error.

String deviceId = Platform.isAndroid ? (await deviceInfoPlugin.androidInfo).androidId : (await deviceInfoPlugin.iosInfo).identifierForVendor;

mohitpubnub commented 3 years ago

It doesn't look like hexadecimal. With apns2, valid hexadecimal device-token is expected.

Anudnya93 commented 1 year ago

Hi @nimda1902 , were you able to resolve this ? I am getting the same error.

Anudnya93 commented 1 year ago

@mohitpubnub How do we resolve it in react native app. Getting same error. I am using Javascript SDK.