Community

Community Forums

Where our customers, developers, and more can come together to help each other with both general and technical questions about our products and services.

iOS opt in only on app restart

Mike Gallouedec

We have Cordova Android/iOS apps. On iOS, we're using XCode 10 and targeting iOS 10, and we use the urbanairship-cordova plugin. There is a quirk I am struggling with on iOS.

When I log into the app my named user is set in Airship. The device shows up fine on device lookup, and appears as opted out for notifications. Thats fine, because we have a preferences page where the user can enable mobile notifications. On that page, we use the `setUserNotificationsEnabled` method of the cordova plugin to update the enabled value. Calling this method brings up the native prompt to allow notifications. Once the user allows notifications, we receive the `notification_opt_in_status` document event, but back in the Airship device lookup dashboard the device is still listed as opted out.

We notice that if we close and reopen the app at this point, the device is marked as opted-in and we can push notifications as normal. This is only an issue on iOS.

Here are the logs from a first app run right after a fresh installation. All i did during this run was open the app, log in, enable notifications, and close the app. My device was successfully registered on Airship (Dev Project), but the device was not opted in even though I enabled notifications.
https://s3.amazonaws.com/respage-temp/first+app+launch+logs.txt

Here are the logs for the very next run. By the time the app finishes loading, my device is marked as opted-in on the Airship dashboard
https://s3.amazonaws.com/respage-temp/second+app+launch+logs.txt

Note: Any lines that contain "[URBAN AIRSHIP]" are debugging lines added by us. I replaced our actual Development API Key with "[DEVELOPMENT API KEY]" placeholder everywhere in the logs.

 

Please sign in to leave a comment.

0
Avatar

Hi Mike,

My name is Darragh, one of the Technical Support Engineers at Airship. Thanks for posting in our forums.

Once you trigger the opt-in function from within your application and if you perform something else, such as navigate around your application, before closing the app, does your application opt-in?

It may not be calling updateResgistration immediately so performing any kind of action with your application after you have triggered the opt-in function to fire may solve your issue. The reason it works when you launch your application because we always fire channel registration on launch.

Two things I have observed from your logs: 

Not opted-in: 

2019-04-18 10:46:07.820758-0400 Respage[1254:326843] [T] -[UAAnalytics addEvent:]_block_invoke [Line 208] Event added: UAEvent ID: FBE72F91-4608-4594-AB89-C1010EBCBA36 type: device_registration time: 1555598767.811680 data: {
}.

Successfully opted-in:

2019-04-18 10:52:16.975381-0400 Respage[1264:328363] [T] -[UAAnalytics addEvent:]_block_invoke [Line 208] Event added: UAEvent ID: 1BB1EEDD-5EF9-418F-B2D6-D73EBE80C9C8 type: device_registration time: 1555599136.944781 data: {
    "channel_id" = "20eff322-31d6-4b50-9e71-55efed239022";
    "device_token" = 1b261bb163794b049d376439f1cab64d1771614698f389db1824b12afe7a5502;
}.

Let me know how your testing goes.

Kind regards,
Darragh Blake
Technical Support Engineer
Airship

Portland | San Francisco | London | Paris | New York | New Delhi

Darragh Blake 0 votes
Comment actions Permalink