Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.0.0] API Updates #1255

Merged
merged 21 commits into from
May 1, 2023
Merged

[5.0.0] API Updates #1255

merged 21 commits into from
May 1, 2023

Conversation

nan-li
Copy link
Contributor

@nan-li nan-li commented Apr 27, 2023

Description

One Line Summary

API updates for the changes not related to observer/handler/listener changes.

Details

Motivation

A desire to align terminologies and naming conventions across the OneSignal SDKs.

Details

The changes are split up into individual commits for more details of each change.

1. API for adding triggers has string values

  • addTrigger and addTriggers public API will only accept string values, not types string/bool/number, etc.
  • No logic changes are needed as the SDK already supports string-only trigger values and evaluates booleans and numerics correctly.
  • Tested scenarios with these triggers set via the dashboard on IAMs:
    • 🟢 myTrigger is true
    • 🟡 myTrigger is 1.58 (must pass in "1.58" and not "1.580" for example, the "is" operator does not support numeric equivalence, it arrives to the SDK as value "1.58")
    • 🟢 myTrigger > 5
    • 🟢 myTrigger > 7.689
    • 🟡 myTrigger >= 7.689 (note margin of error due to rounding, this value actually came to the SDK as 7.689000129699707, so adding a trigger value of "7.689" does not trigger the IAM to display)

2. Make Live Activities namespace

  • Make Live Activities namespace OneSignal.LiveActivities

3. Update privacy consent API names and no public getters

  • Rename requiresPrivacyConsent to consentRequired
  • Rename privacyConsent to consentGiven
  • Remove public getters for these 2 properties
  • Swift cannot have computed write-only properties so instead of OneSignal.consentGiven = true, it will be OneSignal.setConsentGiven(true)

4. Add OneSignal.Notifications.permissionNative

  • Add permissionNative to Notifications namespace which tells if it's provisional, ephemeral, denied, authorized etc
  • Expose enum OSNotificationPermission which has these 5 values

5. Update InAppMessages.paused to not be capitalized

  • For Swift, let's not capitalize the paused boolean: it will be OneSignal.InAppMessages.paused instead of OneSignal.InAppMessages.Paused.

Testing

Manual testing

Physical iPhone 13 on iOS 16.x.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

nan-li added 9 commits April 27, 2023 15:48
* addTrigger and addTriggers public API will only accept string values, not types string/bool/number, etc.
* No logic changes are needed as the SDK already supports string-only trigger values and evaluates booleans and numerics correctly.

Tested scenarios with these triggers set via the dashboard on IAMs:
🟢 myTrigger is true
🟡 myTrigger is 1.58 (must pass in "1.58" and not "1.580" for example, the "is" operator does not support numeric equivalence, it arrives to the SDK as value "1.58")
🟢 myTrigger > 5
🟢 myTrigger > 7.689
🟡 myTrigger >= 7.689 (note margin of error due to rounding, this value actually came to the SDK as 7.689000129699707, so adding a trigger value of "7.689" does not trigger the IAM to display)
* Make Live Activities namespace `OneSignal.LiveActivities`
* Rename `requiresPrivacyConsent` to `consentRequired`
* Rename `privacyConsent` to `consentGiven`
* Remove public getters for these 2 properties
* Swift cannot have computed write-only properties so instead of `OneSignal.consentGiven = true`, it will be `OneSignal.setConsentGiven(true)`
* Add permissionNative which tells if it's provisional, ephemeral, denied, authorized etc
* Expose enum OSNotificationPermission which has 5 values
* These are already part of the OSDebug protocol so no need to state them again
* For Swift, no capitalizing the paused boolean: it will be OneSignal.InAppMessages.paused instead of capital Paused.
* Rename observer from `OSPermissionObserver` to `OSNotificationPermissionObserver`
* Rename and change the method from
`onOSPermissionChanged:(OSPermissionStateChanges)` to `onNotificationPermissionDidChange:(BOOL)`
* The `OSObservable` infrastructure works with objects, and even though we use NSNumber to get around this, once we pass an NSNumber to the app developer's method that expects a BOOL, it does not work.
* Therefore, make another OSBoolObservable just for booleans, and use `NSInvocation` instead of `performSelector` because the latter only works with objects.
* Rename `OSInAppMessageLifecycleHandler` to `OSInAppMessageLifecycleListener`
* The methods will receive specific event types such as `OSInAppMessageDidDisplayEvent` instead of just the `OSInAppMessage`
* Add a remove method `removeLifecycleListener`
* Due to Obj-C not allowing method overloading, add `InAppMessage` to method names, so it doesn't conflict with Notifications displays, but this doesn't apply to Swift as we can refine the swift name.
- onWillDisplayInAppMessage
- onDidDisplayInAppMessage
- onWillDismissInAppMessage
- onDidDismissInAppMessage
* Rename notificationWillShowInForegroundHandler to OSNotificationLifecycleListener
* It will have the `onWillDisplay` event.
nan-li and others added 12 commits April 28, 2023 13:37
* Rename OSPushSubscriptionStateChanges to OSPushSubscriptionChangedState
* Rename event from onOSPushSubscriptionChanged to onPushSubscriptionDidChange
* Use current and previous instead of to and from
* No other logic changes, only naming
* It can just use the `wantsToDisplay` property of the notification it owns.
* Rename click block to `OSInAppMessageClickListener`
* Rename `setClickHandler` to  `addClickListener`
* Add a remove method for the click listener
* OSInAppMessageAction has basically been renamed to OSInAppMessageClickResult
* OSInAppMessageClickEvent will be passed to developers instead of OSInAppMessageAction and the event will contain an in app message and a click result.
OSInAppMessageDelegate  and handleMessageAction not used by anything
* We have some legacy logic about IAM direct influence but if there are multiple click listeners added, we only want this to update once, and not for every listener.
* Rename setNotificationOpenedHandler -> addClickListener, removeClickListener
* Rename object `OSNotificationOpenedResult` -> `OSNotificationClickEvent`
* Rename object `OSNotificationAction` -> `OSNotificationClickResult`
* Support having multiple listeners
…ener_api

[5.0.0] Notification Click Listener - API update
…ver_api

[5.0.0] Push Subscription Observer - API update
…_listener_api

[5.0.0] Notification Foreground Listener - API update
[5.0.0] IAM Lifecycle Listener - API update
…_observer_api

[5.0.0] Notification Permission Observer - API update
@emawby emawby changed the title [5.0.0] API Updates (no listeners or handlers) [5.0.0] API Updates May 1, 2023
@emawby emawby merged commit ac3c98e into major_release_5.0.0 May 1, 2023
@emawby emawby deleted the 5.0.0/api_updates_part_1 branch May 1, 2023 20:31
@emawby emawby mentioned this pull request May 1, 2023
nan-li pushed a commit that referenced this pull request Oct 30, 2023
nan-li pushed a commit that referenced this pull request Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants