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

[Bug]: Subscription Id is empty, not null #922

Open yashdeep-itech opened 2 months ago

yashdeep-itech commented 2 months ago

What happened?

The subscriptionId is unexpectedly empty despite being non-null. This issue has emerged recently; approximately six months ago, the functionality was functioning correctly. I also tried OneSignal.login(), still getting subscription id as empty string

Steps to reproduce?

1. Initialize the OneSignal Flutter plugin in your Flutter project.

      OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
      OneSignal.Debug.setAlertLevel(OSLogLevel.none);
      OneSignal.consentRequired(false);
      OneSignal.initialize("<APP-ID>");

2. Set up observers to listen for changes in subscription status.

       OneSignal.User.pushSubscription.addObserver((state) {
        print("Opted In ${OneSignal.User.pushSubscription.optedIn}");
        print("Push Subscription Id ${OneSignal.User.pushSubscription.id}");
        print(
            "Push Subscription Token ${OneSignal.User.pushSubscription.token}");
        print("Id" + "${state.current.id}");
        print(state.current.jsonRepresentation());
      });

3. Verify the value of subscriptionId:
       print("ID" + "${OneSignal.User.pushSubscription.id}");

What did you expect to happen?

I expected to get subscription id from this line of code OneSignal.User.pushSubscription.id

OneSignal Flutter SDK version

5.2.2

Which platform(s) are affected?

Relevant log output

D/OneSignal(19294): [main] OperationRepo.enqueue(operation: {"name":"create-subscription","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273","subscriptionId":"local-c0643443-528b-4fd7-b317-2f698132d5b9","type":"PUSH","enabled":false,"address":"","status":"NO_PERMISSION"}, flush: false)
D/OneSignal(19294): [main] OperationRepo.enqueue(operation: {"name":"login-user","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273"}, flush: false)
D/OneSignal(19294): [Thread-10] ConfigModelListener: fetching parameters for appId: "<APP-ID>"
D/OneSignal(19294): [main] BackgroundManager cancel background sync
D/OneSignal(19294): [Thread-10] ParamsBackendService.fetchParams(appId: "<APP-ID>", subscriptionId: null)
D/OneSignal(19294): [OpRepo] OperationRepo: internalEnqueue - operation.id: 113ca6fd-fa95-4e9b-b7cd-58334da576cf already exists in the queue.
D/OneSignal(19294): [OpRepo] OperationRepo: internalEnqueue - operation.id: 622a1abf-de45-4004-921d-587d1244c337 already exists in the queue.
D/OneSignal(19294): [DefaultDispatcher-worker-3] HttpClient: Request Sent = GET https://api.onesignal.com/apps/"<APP-ID>"/android_params.js - Body: null - Headers: Accept=[application/vnd.onesignal.v1+json], OneSignal-Install-Id=[cffbd20c-782d-47bf-a5c7-1975d529d7e8], OneSignal-Subscription-Id=[local-c0643443-528b-4fd7-b317-2f698132d5b9], SDK-Version=[onesignal/android/050117], SDK-Wrapper=[onesignal/flutter/050202]
D/OneSignal(19294): [main] SessionService.onFocus() - fired from start: true
D/OneSignal(19294): [main] SessionService: New session started at 1720769172215
D/OneSignal(19294): [main] InfluenceManager.restartSessionIfNeeded(entryAction: APP_OPEN):
D/OneSignal(19294):  channelTrackers: [ChannelTracker{tag=notification_id, influenceType=UNATTRIBUTED, indirectIds=null, directId=null}, ChannelTracker{tag=iam_id, influenceType=UNATTRIBUTED, indirectIds=null, directId=null}]
D/OneSignal(19294): [main] ChannelTracker.getLastReceivedIds: lastChannelObjectReceived: []
D/OneSignal(19294): [main] InfluenceManager.restartSessionIfNeeded: lastIds: []
D/OneSignal(19294): [main] ChannelTracker.getLastReceivedIds: lastChannelObjectReceived: []
D/OneSignal(19294): [main] InfluenceManager.restartSessionIfNeeded: lastIds: []
W/SQLiteLog(19294): (28) double-quoted string literal: "notification"
D/OneSignal(19294): [main] OutcomeEventsController.sessionStarted: Cleaning outcomes for new session
D/OneSignal(19294): [main] OperationRepo.enqueue(operation: {"name":"track-session-start","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273"}, flush: false)
D/OneSignal(19294): [main] NotificationsManager.addPermissionObserver(observer: com.onesignal.notifications.internal.listeners.DeviceRegistrationListener@b5ea8eb)
D/OneSignal(19294): [DefaultDispatcher-worker-1] Attempted to clean 6 month old IAM data, but none exists!
D/OneSignal(19294): [main] InAppMessagesManager.addLifecycleListener(listener: com.onesignal.flutter.OneSignalInAppMessages@f87b648)
D/OneSignal(19294): [main] InAppMessagesManager.addClickListener(listener: com.onesignal.flutter.OneSignalInAppMessages@f87b648)
I/ViewRootImpl@3d510dd[MainActivity](19294): MSG_WINDOW_FOCUS_CHANGED 1 1
D/InputMethodManager(19294): startInputInner - Id : 0
I/InputMethodManager(19294): startInputInner - mService.startInputOrWindowGainedFocus
D/InputMethodManager(19294): startInputInner - Id : 0
D/OneSignal(19294): [DefaultDispatcher-worker-1] initWithContext(context: android.app.Application@f4f1514, appId: null)
D/OneSignal(19294): [DefaultDispatcher-worker-1] initWithContext: SDK already initialized
D/OneSignal(19294): [DefaultDispatcher-worker-1] Retrieving service interface com.onesignal.notifications.internal.restoration.INotificationRestoreProcessor
D/OneSignal(19294): [DefaultDispatcher-worker-1] Already instantiated: com.onesignal.notifications.internal.restoration.impl.NotificationRestoreProcessor@abbf8a8
I/OneSignal(19294): [DefaultDispatcher-worker-1] Restoring notifications
I/WM-WorkerWrapper(19294): Worker result SUCCESS for Work [ id=ca687f57-880f-4573-927f-4dd477a70537, tags={ com.onesignal.notifications.internal.restoration.impl.NotificationRestoreWorkManager$NotificationRestoreWorker } ]
D/OneSignal(19294): [DefaultDispatcher-worker-3] HttpClient: Got Response = GET https://api.onesignal.com/apps/"<APP-ID>"/android_params.js - STATUS: 200 - Body: {"awl_list":{},"android_sender_id":"791849448469","chnl_lst":[],"require_email_auth":true,"require_user_id_auth":true,"outcomes":{"direct":{"enabled":false},"indirect":{"notification_attribution":{"minutes_since_displayed":60,"limit":10},"enabled":false},"unattributed":{"enabled":false}},"receive_receipts_enable":false}
D/OneSignal(19294): [DefaultDispatcher-worker-3] HttpClient: Got Response = Response has etag of W/"85abb4bd21d19fa4b3aa00ffa2bf2030" so caching the response.
I/FirebaseApp(19294): Device unlocked: initializing all Firebase APIs for app ONESIGNAL_SDK_FCM_APP_NAME
W/ynnette.kitche(19294): Long monitor contention with owner Firebase-Messaging-Init (19548) at com.google.android.gms.tasks.Task com.google.firebase.messaging.RequestDeduplicator.getOrStartGetTokenRequest(java.lang.String, com.google.firebase.messaging.RequestDeduplicator$GetTokenRequest)(RequestDeduplicator.java:77) waiters=0 in com.google.android.gms.tasks.Task com.google.firebase.messaging.RequestDeduplicator.getOrStartGetTokenRequest(java.lang.String, com.google.firebase.messaging.RequestDeduplicator$GetTokenRequest) for 953ms
I/OneSignal(19294): [Thread-15] Device registered, push token = eU0oHKTORta6J-iJDIfxPV:APA91bHSIOEKA3XIQ7suGr6eVh-eNSz2cbCWzu78NHzb3LHwDFZknRGwTK_3zE5fPXN_B_JiuV957S1qBrNp7S8Iqr3Zz4bzhvjv5qVxWcMyRq30NiViONte-Mz_mz6bADY_Nf4_BxNR
D/OneSignal(19294): [Thread-15] OperationRepo.enqueue(operation: {"name":"update-subscription","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273","subscriptionId":"local-c0643443-528b-4fd7-b317-2f698132d5b9","type":"PUSH","enabled":false,"address":"eU0oHKTORta6J-iJDIfxPV:APA91bHSIOEKA3XIQ7suGr6eVh-eNSz2cbCWzu78NHzb3LHwDFZknRGwTK_3zE5fPXN_B_JiuV957S1qBrNp7S8Iqr3Zz4bzhvjv5qVxWcMyRq30NiViONte-Mz_mz6bADY_Nf4_BxNR","status":"NO_PERMISSION"}, flush: false)
D/OneSignal(19294): [Thread-15] OperationRepo.enqueue(operation: {"name":"update-subscription","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273","subscriptionId":"local-c0643443-528b-4fd7-b317-2f698132d5b9","type":"PUSH","enabled":true,"address":"eU0oHKTORta6J-iJDIfxPV:APA91bHSIOEKA3XIQ7suGr6eVh-eNSz2cbCWzu78NHzb3LHwDFZknRGwTK_3zE5fPXN_B_JiuV957S1qBrNp7S8Iqr3Zz4bzhvjv5qVxWcMyRq30NiViONte-Mz_mz6bADY_Nf4_BxNR","status":"SUBSCRIBED"}, flush: false)
I/ynnette.kitche(19294): Thread[6,tid=19317,WaitingInMainSignalCatcherLoop,Thread*=0x7948e94000,peer=0x14140000,"Signal Catcher"]: reacting to signal 10
I/ynnette.kitche(19294): 
I/ynnette.kitche(19294): SIGUSR1 forcing GC (no HPROF) and profile save
I/ynnette.kitche(19294): Explicit concurrent copying GC freed 3303(357KB) AllocSpace objects, 6(312KB) LOS objects, 62% free, 3744KB/9888KB, paused 241us,144us total 55.327ms
D/[secipm](19294): mSecIpmManager setProfileLength com.lynnette.kitchen profile:8258
D/OneSignal(19294): [OpRepo] processQueueForever:ops:
D/OneSignal(19294): [bucket:0, retries:0, operation:{"name":"login-user","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273","id":"113ca6fd-fa95-4e9b-b7cd-58334da576cf"}
D/OneSignal(19294): , bucket:0, retries:0, operation:{"name":"create-subscription","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273","subscriptionId":"local-c0643443-528b-4fd7-b317-2f698132d5b9","type":"PUSH","enabled":false,"address":"","status":"NO_PERMISSION","id":"622a1abf-de45-4004-921d-587d1244c337"}
D/OneSignal(19294): , bucket:0, retries:0, operation:{"name":"update-subscription","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273","subscriptionId":"local-c0643443-528b-4fd7-b317-2f698132d5b9","type":"PUSH","enabled":false,"address":"eU0oHKTORta6J-iJDIfxPV:APA91bHSIOEKA3XIQ7suGr6eVh-eNSz2cbCWzu78NHzb3LHwDFZknRGwTK_3zE5fPXN_B_JiuV957S1qBrNp7S8Iqr3Zz4bzhvjv5qVxWcMyRq30NiViONte-Mz_mz6bADY_Nf4_BxNR","status":"NO_PERMISSION","id":"bf81de60-2d4e-4776-aabe-59984939317c"}
D/OneSignal(19294): , bucket:0, retries:0, operation:{"name":"update-subscription","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273","subscriptionId":"local-c0643443-528b-4fd7-b317-2f698132d5b9","type":"PUSH","enabled":true,"address":"eU0oHKTORta6J-iJDIfxPV:APA91bHSIOEKA3XIQ7suGr6eVh-eNSz2cbCWzu78NHzb3LHwDFZknRGwTK_3zE5fPXN_B_JiuV957S1qBrNp7S8Iqr3Zz4bzhvjv5qVxWcMyRq30NiViONte-Mz_mz6bADY_Nf4_BxNR","status":"SUBSCRIBED","id":"332d9583-df7c-4bc0-9f4f-4baf13f3d0da"}
D/OneSignal(19294): ]
D/OneSignal(19294): [OpRepo] LoginUserOperationExecutor(operation: [{"name":"login-user","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273","id":"113ca6fd-fa95-4e9b-b7cd-58334da576cf"}, {"name":"create-subscription","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273","subscriptionId":"local-c0643443-528b-4fd7-b317-2f698132d5b9","type":"PUSH","enabled":false,"address":"","status":"NO_PERMISSION","id":"622a1abf-de45-4004-921d-587d1244c337"}, {"name":"update-subscription","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273","subscriptionId":"local-c0643443-528b-4fd7-b317-2f698132d5b9","type":"PUSH","enabled":false,"address":"eU0oHKTORta6J-iJDIfxPV:APA91bHSIOEKA3XIQ7suGr6eVh-eNSz2cbCWzu78NHzb3LHwDFZknRGwTK_3zE5fPXN_B_JiuV957S1qBrNp7S8Iqr3Zz4bzhvjv5qVxWcMyRq30NiViONte-Mz_mz6bADY_Nf4_BxNR","status":"NO_PERMISSION","id":"bf81de60-2d4e-4776-aabe-59984939317c"}, {"name":"update-subscription","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273","subscriptionId":"local-c0643443-528b-4fd7-b317-2f698132d5b9","type":"PUSH","enabled":true,"address":"eU0oHKTORta6J-iJDIfxPV:APA91bHSIOEKA3XIQ7suGr6eVh-eNSz2cbCWzu78NHzb3LHwDFZknRGwTK_3zE5fPXN_B_JiuV957S1qBrNp7S8Iqr3Zz4bzhvjv5qVxWcMyRq30NiViONte-Mz_mz6bADY_Nf4_BxNR","status":"SUBSCRIBED","id":"332d9583-df7c-4bc0-9f4f-4baf13f3d0da"}])
D/OneSignal(19294): [DefaultDispatcher-worker-1] HttpClient: Request Sent = POST https://api.onesignal.com/apps/"<APP-ID>"/users - Body: {"subscriptions":[{"type":"AndroidPush","token":"eU0oHKTORta6J-iJDIfxPV:APA91bHSIOEKA3XIQ7suGr6eVh-eNSz2cbCWzu78NHzb3LHwDFZknRGwTK_3zE5fPXN_B_JiuV957S1qBrNp7S8Iqr3Zz4bzhvjv5qVxWcMyRq30NiViONte-Mz_mz6bADY_Nf4_BxNR","enabled":true,"notification_types":1,"sdk":"050117","device_model":"SM-M317F","device_os":"12","rooted":false,"net_type":0,"carrier":"airtel","app_version":"1"}],"properties":{"timezone_id":"Asia\/Kolkata","language":"en"},"refresh_device_metadata":true} - Headers: Accept=[application/vnd.onesignal.v1+json], Content-Type=[application/json; charset=UTF-8], OneSignal-Install-Id=[cffbd20c-782d-47bf-a5c7-1975d529d7e8], OneSignal-Subscription-Id=[local-c0643443-528b-4fd7-b317-2f698132d5b9], SDK-Version=[onesignal/android/050117], SDK-Wrapper=[onesignal/flutter/050202]
D/OneSignal(19294): [DefaultDispatcher-worker-1] HttpClient: Got Response = POST https://api.onesignal.com/apps/"<APP-ID>"/users - FAILED STATUS: 401
W/OneSignal(19294): [DefaultDispatcher-worker-1] HttpClient: Got Response = POST - STATUS: 401 - Body: {"errors":[{"code":"auth-1","title":"This operation requires 'Authorization' in the HTTP header"}]}
D/OneSignal(19294): [OpRepo] OperationRepo: execute response = FAIL_UNAUTHORIZED
E/OneSignal(19294): Operation execution failed without retry: [{"name":"login-user","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273","id":"113ca6fd-fa95-4e9b-b7cd-58334da576cf"}, {"name":"create-subscription","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273","subscriptionId":"local-c0643443-528b-4fd7-b317-2f698132d5b9","type":"PUSH","enabled":false,"address":"","status":"NO_PERMISSION","id":"622a1abf-de45-4004-921d-587d1244c337"}, {"name":"update-subscription","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273","subscriptionId":"local-c0643443-528b-4fd7-b317-2f698132d5b9","type":"PUSH","enabled":false,"address":"eU0oHKTORta6J-iJDIfxPV:APA91bHSIOEKA3XIQ7suGr6eVh-eNSz2cbCWzu78NHzb3LHwDFZknRGwTK_3zE5fPXN_B_JiuV957S1qBrNp7S8Iqr3Zz4bzhvjv5qVxWcMyRq30NiViONte-Mz_mz6bADY_Nf4_BxNR","status":"NO_PERMISSION","id":"bf81de60-2d4e-4776-aabe-59984939317c"}, {"name":"update-subscription","appId":"<APP-ID>","onesignalId":"local-f216de86-6365-4015-9bc1-21b492fdf273","subscriptionId":"local-c0643443-528b-4fd7-b317-2f698132d5b9","type":"PUSH","enabled":true,"address":"eU0oHKTORta6J-iJDIfxPV:APA91bHSIOEKA3XIQ7suGr6eVh-eNSz2cbCWzu78NHzb3LHwDFZknRGwTK_3zE5fPXN_B_JiuV957S1qBrNp7S8Iqr3Zz4bzhvjv5qVxWcMyRq30NiViONte-Mz_mz6bADY_Nf4_BxNR","status":"SUBSCRIBED","id":"332d9583-df7c-4bc0-9f4f-4baf13f3d0da"}]
D/OneSignal(19294): [OpRepo] retryAfterSeconds: null
D/OneSignal(19294): [OpRepo] processQueueForever:ops:
D/OneSignal(19294): null
D/SurfaceView@9d1c2ee(19294): updateSurface: surface is not valid
D/SurfaceView@9d1c2ee(19294): updateSurface: surface is not valid
D/OneSignal(19294): [main] ApplicationService.onActivityStopped(1,APP_OPEN): com.lynnette.kitchen.MainActivity@8c1f959
D/OneSignal(19294): [main] ApplicationService: current activity=null
D/OneSignal(19294): [main] ApplicationService.handleLostFocus: application is now out of focus
D/OneSignal(19294): [main] LocationController scheduleUpdate not possible, location shared not enabled
D/OneSignal(19294): [main] OSBackgroundSync scheduleSyncServiceAsJob:atTime: 30000
I/OneSignal(19294): [main] OSBackgroundSync scheduleSyncServiceAsJob:result: 1
D/OneSignal(19294): [main] SessionService.onUnfocused adding time 94603 for total: 94603
D/OneSignal(19294): [main] ApplicationService.onActivityStarted(0,APP_CLOSE): com.lynnette.kitchen.MainActivity@8c1f959
D/OneSignal(19294): [main] ApplicationService: current activity=com.lynnette.kitchen.MainActivity@8c1f959
D/OneSignal(19294): [main] ApplicationService.handleFocus: application is now in focus, nextResumeIsFirstActivity=false
D/OneSignal(19294): [main] BackgroundManager cancel background sync
D/OneSignal(19294): [main] SessionService.onFocus() - fired from start: false
D/OneSignal(19294): [main] InfluenceManager.attemptSessionUpgrade(entryAction: APP_OPEN, directId: null)
D/OneSignal(19294): [main] InfluenceManager.attemptSessionUpgrade: try UNATTRIBUTED to INDIRECT upgrade
D/OneSignal(19294): [main] ChannelTracker.getLastReceivedIds: lastChannelObjectReceived: []
D/OneSignal(19294): [main] ChannelTracker.getLastReceivedIds: lastChannelObjectReceived: []
D/OneSignal(19294): [main] InfluenceManager.attemptSessionUpgrade: Trackers after update attempt: [ChannelTracker{tag=notification_id, influenceType=UNATTRIBUTED, indirectIds=null, directId=null}, ChannelTracker{tag=iam_id, influenceType=UNATTRIBUTED, indirectIds=null, directId=null}]
I/ViewRootImpl@3d510dd[MainActivity](19294): stopped(false) old=false
D/OneSignal(19294): [main] ApplicationService.onActivityResumed(1,APP_OPEN): com.lynnette.kitchen.MainActivity@8c1f959
D/OneSignal(19294): [main] NotificationsManager.addForegroundLifecycleListener(listener: com.onesignal.flutter.OneSignalNotifications@b92fd6a)
D/OneSignal(19294): [main] NotificationsManager.addPermissionObserver(observer: com.onesignal.flutter.OneSignalNotifications@b92fd6a)
I/flutter (19294): {
I/flutter (19294):   "id": "",
I/flutter (19294):   "token": "eU0oHKTORta6J-iJDIfxPV:APA91bHSIOEKA3XIQ7suGr6eVh-eNSz2cbCWzu78NHzb3LHwDFZknRGwTK_3zE5fPXN_B_JiuV957S1qBrNp7S8Iqr3Zz4bzhvjv5qVxWcMyRq30NiViONte-Mz_mz6bADY_Nf4_BxNR",
I/flutter (19294):   "optedIn": true
I/flutter (19294): }

Code of Conduct

DmitryGaimaldinov commented 1 month ago

Same issue. In my case it doesn't always happen. But sometimes it happens after changing appId in appication. We have one appId for production environment and another one for development. Changing environments causes changing appid in already installed application. After this empty subscription id starts returning. Clearing storage / Deleting application helps but I wish it weren't needed

P.S. One signal flutter sdk version is 5.2.0