urbanairship / ios-library

Urban Airship iOS SDK
http://urbanairship.com
Apache License 2.0
478 stars 265 forks source link

Preference Center toggles don't save (16.11.3+) #377

Closed joshuapoq closed 10 months ago

joshuapoq commented 11 months ago

Preliminary Info

What Airship dependencies are you using?

16.11.3 ..< 17.0.0

Report

What unexpected behavior are you seeing?

On 16.11.2 the Preference Center works (it remembers the toggled option). On 16.11.3+ it no longer works. Version diff.

EDIT: Also looks like it's not working on 17 either? (but we can't upgrade yet)

What is the expected behavior?

The preference should be remembered.

What are the steps to reproduce the unexpected behavior?

Do you have logging for the issue?

When I launch the app I see a couple of these (not sure if relevant):

[E] AirshipCore/AirshipKeychainAccess.swift updateThisDeviceOnly(identifier:service:) [Line 295] Failed to update keychain value com.urbanairship.deviceID status:-50

When I open the preference center for the first time:

[E] AirshipCore/PreferenceDataStore.swift safeCodable(forKey:) [Line 208] Failed to read codable for key Contact.anonContactData
rlepinski commented 11 months ago

Those are some unusual errors. When you say close it and reopen are you restarting the app or just the preference center view? Could you give me verbose logs showing the issue? https://docs.airship.com/platform/mobile/logging/?groupid=ios-swift (for 16.x you need to set it to trace)

joshuapoq commented 11 months ago

When you say close it and reopen are you restarting the app or just the preference center view? When we close and reopen the view controller (via navigation controller pop, push).

Below is the log after the app is launched where I navigate to the Preference Center, toggle a preference, then back.

[D] AirshipCore/ContactAPIClient.swift fetchSubscriptionLists(_:completionHandler:) [Line 571] Retrieving subscription lists associated with a contact
[D] AirshipCore/ContactAPIClient.swift fetchSubscriptionLists(_:completionHandler:) [Line 589] Retrieved lists with response: <NSHTTPURLResponse: 0x6000007cef00> { URL: https://device-api.urbanairship.com/api/subscription_lists/contacts/82326e9e-1c5d-4690-84b8-244beb2e15cd } { Status Code: 200, Headers {
    "Alt-Svc" =     (
        "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"
    );
    "Cache-Control" =     (
        "max-age=0"
    );
    "Content-Encoding" =     (
        gzip
    );
    "Content-Length" =     (
        55
    );
    "Content-Type" =     (
        "application/vnd.urbanairship+json;version=3"
    );
    Date =     (
        "Fri, 20 Oct 2023 15:15:54 GMT"
    );
    Expires =     (
        "Fri, 20 Oct 2023 15:15:54 GMT"
    );
    "Last-Modified" =     (
        "Fri, 20 Oct 2023 15:15:54 GMT"
    );
    Vary =     (
        "Accept-Encoding"
    );
    Via =     (
        "1.1 google"
    );
    "data-attribute" =     (
        "subscription_lists"
    );
} }
[D] AirshipCore/Contact.swift resolveSubscriptionLists(_:) [Line 707] Fetched lists finished with response: HTTPResponse(status=200)
[D]  -[UAAutomationEngine updateTriggersWithScheduleID:type:argument:incrementAmount:] [Line 662] Updating triggers with type: 6
[T]  -[UAAutomationEngine updateTriggersWithScheduleID:type:argument:incrementAmount:]_block_invoke_2 [Line 717] Automation execution time: 0.000604 seconds, triggers: 0, triggered schedules: 0
[D] AirshipCore/Analytics.swift addEvent(_:) [Line 434] Adding screen_tracking event B702A788-4E5D-4222-8DE2-AC4786AA3604
[T] AirshipCore/EventManager.swift scheduleUpload(delay:) [Line 241] Upload already scheduled for an earlier time.
[T] AirshipCore/Analytics.swift addEvent(_:) [Line 436] Event added: <UAScreenTrackingEvent: 0x600001816e00>
[D] AirshipCore/EventStore.swift storeEvent(withID:eventType:eventTime:eventBody:sessionID:context:) [Line 207] Event saved: B702A788-4E5D-4222-8DE2-AC4786AA3604
[T] AirshipCore/BackgroundTasks.swift beginTask(_:expirationHandler:) [Line 37] Background task started: Airship.TaskManager -  Request: Contact.update
[T] AirshipCore/TaskManager.swift attemptRequest(_:nextBackOff:) [Line 275] Task Contact.update started
[D] AirshipCore/ContactAPIClient.swift resolve(channelID:completionHandler:) [Line 97] Resolving contact with channel ID f990f51e-1b55-44f9-8b0e-6ff4d540a8a6
[D] AirshipCore/ContactAPIClient.swift resolve(channelID:completionHandler:) [Line 130] Resolved contact with response: <NSHTTPURLResponse: 0x6000007dc4a0> { URL: https://device-api.urbanairship.com/api/contacts/resolve } { Status Code: 200, Headers {
    "Alt-Svc" =     (
        "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"
    );
    "Cache-Control" =     (
        "max-age=0"
    );
    "Content-Length" =     (
        83
    );
    "Content-Type" =     (
        "application/vnd.urbanairship+json;version=3"
    );
    Date =     (
        "Fri, 20 Oct 2023 15:15:57 GMT"
    );
    Expires =     (
        "Fri, 20 Oct 2023 15:15:57 GMT"
    );
    "Last-Modified" =     (
        "Fri, 20 Oct 2023 15:15:57 GMT"
    );
    Via =     (
        "1.1 google"
    );
    "data-attribute" =     (
        "is_anonymous"
    );
} }
[D] AirshipCore/Contact.swift logOperationResult(operation:response:error:) [Line 1,068] Contact update for operation: ContactOperation(type: AirshipCore.OperationType.resolve, payload: nil) succeeded with response: HTTPResponse(status=200)
[T] AirshipCore/TaskManager.swift attemptRequest(_:nextBackOff:) [Line 235] Task Contact.update finished
[T] AirshipCore/BackgroundTasks.swift beginTask(_:expirationHandler:) [Line 22] Ending background task: Airship.TaskManager -  Request: Contact.update
[T] AirshipCore/BackgroundTasks.swift beginTask(_:expirationHandler:) [Line 37] Background task started: Airship.TaskManager -  Request: Contact.update
[T] AirshipCore/TaskManager.swift attemptRequest(_:nextBackOff:) [Line 275] Task Contact.update started
[D] AirshipCore/ContactAPIClient.swift update(identifier:tagGroupUpdates:attributeUpdates:subscriptionListUpdates:completionHandler:) [Line 246] Updating contact with identifier 82326e9e-1c5d-4690-84b8-244beb2e15cd
[D] AirshipCore/ContactAPIClient.swift update(identifier:tagGroupUpdates:attributeUpdates:subscriptionListUpdates:completionHandler:) [Line 272] Update finished with response: <NSHTTPURLResponse: 0x6000007dd2a0> { URL: https://device-api.urbanairship.com/api/contacts/82326e9e-1c5d-4690-84b8-244beb2e15cd } { Status Code: 403, Headers {
    "Alt-Svc" =     (
        "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"
    );
    "Content-Length" =     (
        55
    );
    "Content-Type" =     (
        "application/vnd.urbanairship+json;version=3"
    );
    Date =     (
        "Fri, 20 Oct 2023 15:15:57 GMT"
    );
    Via =     (
        "1.1 google"
    );
} }
[D] AirshipCore/Contact.swift logOperationResult(operation:response:error:) [Line 1,070] Contact update for operation: ContactOperation(type: AirshipCore.OperationType.update, payload: Optional(AirshipCore.UpdatePayload(tagUpdates: nil, attrubuteUpdates: nil, subscriptionListsUpdates: Optional([AirshipCore.ScopedSubscriptionListUpdate(listId: "discounts___promotions", type: AirshipCore.SubscriptionListUpdateType.subscribe, scope: app, date: 2023-10-20 15:15:57 +0000)])))) failed with response: HTTPResponse(status=403)
[T] AirshipCore/TaskManager.swift attemptRequest(_:nextBackOff:) [Line 235] Task Contact.update finished
[T] AirshipCore/BackgroundTasks.swift beginTask(_:expirationHandler:) [Line 22] Ending background task: Airship.TaskManager -  Request: Contact.update
[D]  -[UAAutomationEngine updateTriggersWithScheduleID:type:argument:incrementAmount:] [Line 662] Updating triggers with type: 6
[T]  -[UAAutomationEngine updateTriggersWithScheduleID:type:argument:incrementAmount:]_block_invoke_2 [Line 717] Automation execution time: 0.000642 seconds, triggers: 0, triggered schedules: 0
[D] AirshipCore/Analytics.swift addEvent(_:) [Line 434] Adding screen_tracking event 456ED66B-2EC8-46E8-BD8D-47EF6810C118
[T] AirshipCore/EventManager.swift scheduleUpload(delay:) [Line 241] Upload already scheduled for an earlier time.
[T] AirshipCore/Analytics.swift addEvent(_:) [Line 436] Event added: <UAScreenTrackingEvent: 0x600001792d00>
[D] AirshipCore/EventStore.swift storeEvent(withID:eventType:eventTime:eventBody:sessionID:context:) [Line 207] Event saved: 456ED66B-2EC8-46E8-BD8D-47EF6810C118

I can see the update contact is failing with a 403 and I guess that's causing this issue? But what has changed in 16.11.3 to cause / expose this?

joshuapoq commented 11 months ago

It actually 'saves' after doing it 3 times in succession. So I wonder if this is just a slow async observation?

  1. Navigate to Preference Center.
  2. Toggle a Preference to on.
  3. Press back.
  4. Repeat 2 more times.
rlepinski commented 11 months ago

Not sure why that release would cause issue but I think you are missing a permission, let me see if i can find it. Give me 5 mins

rlepinski commented 11 months ago

https://go.urbanairship.com/apps//api/#named-tab-section

Is that enabled for you?

joshuapoq commented 10 months ago

I saw that and tried that before logging off. I guess it didn't take effect immediately as it's working fine now. Thanks / apologies; will close this issue.

rlepinski commented 10 months ago

Just happy we could resolve this without a code change.

I think 16.11.2 and older use to update the subscription lists when the change operation was complete, success or not. On 16.11.3+ we only do it on success now. So 16.11.3 is doing a better thing but it appeared to work on 16.11.2