Skip to content

[Feature] Add callbacks to setLanguage #568

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

Merged
merged 3 commits into from
Jun 13, 2022
Merged

Conversation

nan-li
Copy link
Contributor

@nan-li nan-li commented Jun 10, 2022

Description

One Line Summary

Adds callbacks for setting language (setLanguage method).

Details

Motivation

Provides developers with success and failure callbacks.

Scope

  • Add setLanguage success and failure callbacks to Android and iOS methods.
  • On Android, if multiple channels are set (ie push, email, SMS), the developer's callback will fire once for the first successful or failed channel and subsequent success or failure callbacks will not be invoked.
  • On iOS, if multiple channels are set (ie push, email, SMS), the callback will be invoked once with the states of all the channels.
  • When testing Android, the onSuccess response from the native SDK is always null. When this is null, I pass through a custom object, because passing through the null object crashes in Flutter.
    {'success' : 'true', 'message' : 'Successfully set language.'}
  • Android always passes through a null response, because this line always has a null language.

How to Use

    OneSignal.shared.setLanguage("fr").then((response) { // Example of setting the language to French.
        print("Successfully set language with response: $response");
    }).catchError((error) {
        print("Failed to set language with error: $error");
    });

Testing

Manual testing

Tested setting various languages on iOS and Android.

  • ✅ Tested setting a language without using any callbacks.
  • ✅ Tested setting a language that accepts the response and catches the failure.
  • ✅ Tested setting email and SMS first, then setting a language. See below for the responses the developer receives.
// Android success
{success: true, message: Successfully set language.}

// iOS success
{email: {success: true}, push: {success: true}}

// Android failure example: turn off wifi and data
PlatformException(OneSignal, Encountered an error when setLanguage: Failed to set language., null, null)

// iOS failure example: turn off wifi and data
// Unfortunately, the flutterError does not give much detail.
PlatformException(0, The operation couldn’t be completed. (com.onesignal.language error 0.), null, null)

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 3 commits June 10, 2022 10:51
- For consistency with the other public methods, let's add a doc comment to the setLanguage method
- Android: added OSFlutterSetLanguageHandler that implements the OSSetLanguageCompletionHandler
- Add a field and button to the example app to allow setting language.
@nan-li nan-li marked this pull request as ready for review June 10, 2022 22:32
@nan-li nan-li requested review from tanaynigam, emawby and jkasten2 June 10, 2022 22:33
Copy link
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 4 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @emawby and @tanaynigam)

@nan-li nan-li merged commit 0c81d09 into main Jun 13, 2022
@nan-li nan-li deleted the feat/add_set_language_callback branch June 13, 2022 21:45
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.

3 participants