braze-inc / braze-cordova-sdk

Public repo for the Braze Cordova SDK
https://www.braze.com
Other
21 stars 63 forks source link

Push registration - Manual call #20

Closed asangadev closed 6 years ago

asangadev commented 6 years ago

Hi @radixdev,

Platform iOS: We are planning to ask the push registration permission with a button tap. So basically we want to disable the automatic feature that comes with the plugin.

We have found below:

On iOS we can trigger this only once, so we need to ask for this permission on the right section of the app.

Can we simply call (what parameters we can pass?): registerAppboyPushMessages()

Please advise.

radixdev commented 6 years ago

Hello @asangadev ,

To disable automatic iOS push registration, please follow https://www.braze.com/documentation/Cordova/iOS/#removing-automatic-push-setup-ios. To manually register for iOS push notifications, follow the steps outlined via https://www.braze.com/documentation/iOS/#step-3-register-for-push-notifications.

Let us know if these steps work for you.

asangadev commented 6 years ago

Hi @radixde,

Thanks for getting back to us. Is there any Javascript method (that we can trigger the core function)? We would like to control this via Javascript.

Cheers!

radixdev commented 6 years ago

We do not have a way to manually request the iOS push permission via the plugin. You'll have to modify the plugin to allow for the manual registration to occur via Javascript.

asangadev commented 6 years ago

Hi guys,

We are switching from a different service provider to Braze. Our app is built on Phonegap and we are currently doing all the tests on our trial version of Braze.

  1. Manual push call: Is this something you guys can help with? May be a plugin update?

  2. Currently we have our app live on both Play and App stores. So we have push enabled devices with our current system. After we migrated to Braze, what will happen to the people who already accepted the push permission? Are they automatically registered under our new Braze account?

Please advise.

radixdev commented 6 years ago

You'll have to email support@braze.com to guide you through the push registration migration.

For the manual push call:

  1. Clone the cordova plugin to make these plugin changes and import that modified version into your project.

  2. Remove the automatic prompt from https://github.com/Appboy/appboy-cordova-sdk/blob/master/src/ios/AppboyPlugin.m#L45-L65

  3. Update the AppboyPlugin.js to add a show push prompt or equivalent method. I.e.

    AppboyPlugin.prototype.iosShowPushPrompt = function () {
    cordova.exec(null, null, "AppboyPlugin", "iosShowPushPrompt", []);
    }
  4. Update the AppboyPlugin.m file to implement the iosShowPushPrompt method.

- (void)iosShowPushPrompt:(CDVInvokedUrlCommand *)command {
    UIUserNotificationType notificationSettingTypes = (UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound);
    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_9_x_Max) {
      UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
      // If the delegate hasn't been set yet, set it here in the plugin
      if (center.delegate == nil) {
        center.delegate = [UIApplication sharedApplication].delegate;
      }
      [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge)
                            completionHandler:^(BOOL granted, NSError * _Nullable error) {
                              NSLog(@"Permission granted.");
      }];
      [[UIApplication sharedApplication] registerForRemoteNotifications];
    } else if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) {
      UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:notificationSettingTypes categories:nil];
      [[UIApplication sharedApplication] registerForRemoteNotifications];
      [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    } else {
      [[UIApplication sharedApplication] registerForRemoteNotificationTypes: notificationSettingTypes];
    }
}
  1. At this point, you should be able to call iosShowPushPrompt on the appboy plugin via javascript to show the push prompt
asangadev commented 6 years ago

I have setup a separate repo: https://github.com/asangadev/appboy-cordova-sdk/commit/0a5800b3868434da37713ba6bd3d564e09b455aa

Cheers!

asangadev commented 6 years ago

Hi @radixdev ,

Could you please help us with below?

screen shot 2018-05-01 at 11 41 02 am

radixdev commented 6 years ago

Move that function bracket on line 67 to be above the method definition. Currently you have a method within another method.