Description:
Good day! A situation has arisen when the playerID does not have time to be initialized at the moment when it is already needed. How to wait for its initialization?
Environment
Flutter 1.20.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision bbfbf1770c (2 weeks ago) • 2020-08-13 08:33:09 -0700
Engine • revision 9d5b21729f
Tools • Dart 2.9.1
Steps to Reproduce Issue:
final status = await _oneSignal.getPermissionSubscriptionState();
final playerId = status.subscriptionStatus?.userId;
PlayerID will be NULL until a request is sent to https://api.onesignal.com/players
Logs:
WARNING: OneSignal has detected that your application delegate implements a deprecated method (application:didReceiveLocalNotification:). Please note that this method has been officially deprecated and the OneSignal SDK will no longer call it. You should use UNUserNotificationCenter instead
Waiting for iPhone SE (2nd generation) to report its views...
Debug service listening on ws://127.0.0.1:52092/pAoChexXtu8=/ws
Syncing files to device iPhone SE (2nd generation)...
VERBOSE: registerForPushNotifications Called:waitingForApnsResponse: 1
VERBOSE: Initializing the OneSignal Flutter SDK (2.2.0)
VERBOSE: init redisplayedInAppMessages with: {
}
VERBOSE: Called init with app ID: b0f99f81-45aa-46f7-8f0e-4a76cbe57d80
DEBUG: Downloading iOS parameters for this application
VERBOSE: registering for Application Lifecycle notifications
WARNING: OneSignal has detected that your application delegate implements a deprecated method (application:didReceiveLocalNotification:). Please note that this method has been officially deprecated and the OneSignal SDK will no longer call it. You should use UNUserNotificationCenter instead
VERBOSE: network response (OSRequestGetIosParams): {
outcomes = {
direct = {
enabled = 0;
};
indirect = {
enabled = 0;
"notification_attribution" = {
limit = 10;
"minutes_since_displayed" = 60;
};
};
unattributed = {
enabled = 0;
};
};
"receive_receipts_enable" = 1;
"uses_provisional_auth" = 0;
}
VERBOSE: application/scene willResignActive
VERBOSE: application/scene willResignActive
DEBUG: OneSignalLocation sendAndClearLocationListener listeners: (
)
DEBUG: OneSignalLocation sendAndClearLocationListener listeners: (
)
VERBOSE: updateNotificationTypes called: 15
VERBOSE: startedRegister: 1
VERBOSE: getNotificationTypes:mSubscriptionStatus: -1
VERBOSE: application/scene didBecomeActive
DEBUG: Application Foregrounded started
DEBUG: cancelFocusCall of {
}
VERBOSE: application/scene didBecomeActive
DEBUG: Outcomes cleared for current session
DEBUG: OneSignal SessionManager restartSessionIfNeeded with entryAction:: 1 channelTrackers: (
"OSChannelTracker tag: notification_id influenceType: UNATTRIBUTED indirectIds: (null) directIds: (null)",
"OSChannelTracker tag: iam_id influenceType: UNATTRIBUTED indirectIds: (null) directIds: (null)"
)
DEBUG: OSChannelTracker for: notification_id lastChannelObjectReceived: (null)
DEBUG: OneSignal SessionManager restartSessionIfNeeded lastIds: (
)
DEBUG: OSChannelTracker for: iam_id lastChannelObjectReceived: (null)
DEBUG: OneSignal SessionManager restartSessionIfNeeded lastIds: (
)
DEBUG: OneSignal SessionManager sendSessionEndingWithInfluences with influences: (
)
VERBOSE: getNotificationTypes:mSubscriptionStatus: -1
DEBUG: provision not found
VERBOSE: Calling OneSignal create/on_session
VERBOSE: Attaching device location to 'on_session' request payload
VERBOSE: HTTP Request (OSRequestRegisterUser) with URL: https://api.onesignal.com/players, with parameters: {
"app_id" : "b0f99f81-45aa-46f7-8f0e-4a76cbe57d80",
"net_type" : 0,
"loc_acc" : 5,
"as_id" : "00000000-0000-0000-0000-000000000000",
"ios_bundle" : "com.sample.onesignal",
"long" : -122.406417,
"device_type" : 0,
"sdk_type" : "flutter",
"sdk" : "021502",
"lat" : 37.785834000000001,
"language" : "en",
"device_os" : "13.6",
"game_version" : "31",
"timezone" : 18000,
"ad_id" : "C83F2181-32C0-4E1C-A04A-954F7D16707B",
"notification_types" : -14,
"device_model" : "Simulator iPhone",
"loc_acc_vert" : -1
}
VERBOSE: network response (OSRequestRegisterUser): {
id = "f35f5c35-6048-4de4-9926-8bd17d2b39ee";
success = 1;
}
Request <OSRequestRegisterUser: 0x600002937300> success result {
id = "f35f5c35-6048-4de4-9926-8bd17d2b39ee";
success = 1;
}
VERBOSE: on_session result: {
push = {
id = "f35f5c35-6048-4de4-9926-8bd17d2b39ee";
success = 1;
};
}
VERBOSE: getNotificationTypes:mSubscriptionStatus: -1
VERBOSE: getNotificationTypes:mSubscriptionStatus: -1
Howdy,
The best way to do this is to wait until the subscription observer fires.
Hope that helps!
And how do I wait for the subscription observer to fire?
Howdy,
The best way to do this is to wait until the subscription observer fires.Hope that helps!
@rgomezp, this didn't solve my problem. I want to keep the application at the moment of showing the splash screen, waiting for the playerId to be initialized. It works correctly on Android, the problem is only on iOS.
Nothing prevents me from using a listener, but just initializing the OneSignal instance works differently depending on the platform. On Android, playerId is waiting for initialization, but not on iOS.
@Holofox I am wondering how were you able to fix this issue?
@Lawati97, at the moment, I'm calling the method in a loop with some delay (polling), waiting for the response with the playerId.
@Holofox Does that slow down the performance of an application?
@Lawati97, the performance does not decrease, just some users will have to wait 10-15 seconds one time.
@Holofox I see, thank you