Cordova > Advanced

General

Migrating from com.batch.cordova 1.x

Batch's cordova plugin 2.0.0 update being a major version, it brings some breaking change to existing implementations:

  • batch.push.setGCMSenderId() has been removed. Android now uses FCM, which requires you to add a google-services.json file to your project. More info here.
  • "setCanUseAndroidID" has been removed from the config object. You can safely leave the key, but it will be ignored.

For any other supported API use cases, your code requires no change.

Migrating from batch.userProfile

If you've previously used batch.userProfile, you can easily use Batch User. You will still be able to set a custom region, language or identifier with the new API.

The main difference between Batch User and BatchUserProfile is that you'll now be required to use an editor object in order to make changes, and then save them. This transactional behaviour brings additional thread-safety and better performance.

That way, what used to be:

// Use the user profile to set custom language and data 
batch.userProfile.setLanguage("en"); // Language must be 2 chars, lowercase, ISO 639 formatted
batch.userProfile.setRegion("US"); // Region must be 2 chars, uppercase, ISO 3166 formatted
batch.userProfile.setCustomID("john.doe");

will become this:

batch.user.getEditor()
    .setLanguage("en") // Language must be 2 chars, lowercase, ISO 639 formatted
    .setRegion("US") // Region must be 2 chars, uppercase, ISO 3166 formatted
    .setIdentifier("john.doe")
    .save(); // Don't forget to save the changes!

batch.userProfile is now deprecated, but will continue to work. We still suggest you migrate in the near future, so you can take advantage of the new capabilities.