-
Notifications
You must be signed in to change notification settings - Fork 22
Migration Guide
This is a migration guide for existing Ionic v1 apps to migrate from the deprecated ionic-platform-web-client to @ionic/cloud. The update brings a much simpler config system as well as some breaking changes.
Note: The Cloud Client is still in beta, and this document may change as new beta releases come out.
- We are deprecating the installation of the Cloud Client via bower. The new
@ionic/cloudpackage on npm should be used going forward. - We are essentially requiring angular 1 apps to use the angular 1 services (
$ionicPush, etc.) instead of the vanilla ES5 classes (Ionic.Push). We changed how these classes were instantiated (by using dependency injection), and thus doingnew Ionic.Push()et al. will simply not work. - Analytics was removed from the client. A separate analytics solution will be reintroduced soon.
- Our source code is now written in Typescript, but we will still be exporting the bundled Cloud Client as usual.
- We are, however, removing the
Promisedefinition from our bundle and expecting it to be defined globally. It is defined in iOS Safari and Android 4.4.4+ (http://caniuse.com/#feat=promises). For peace of mind, a shim can be installed and included before the Cloud Client, such as es6-promise or bluebird. - The values promises resolve with have changed across the services. Most success handlers don't give any parameters (because they didn't need to) and all error handlers now return an
Errorinstance. - The Angular modules have been consolidated. (
ionic.service.core,ionic.service.push, etc. are nowionic.cloud). -
Ionic.Core.config.getURL('platform-api')is now$ionicCloudConfig.getURL('api') - Removed
onReady()method of all services. Check out the events you can subscribe to with the new event emitter. See the docs. -
Ionic.io()has been removed (just remove it from your code) -
Ionic.getService/Ionic.addService/Ionic.removeServicehave been removed -
persistentStorageangular provider has been removed - Alpha services migration functionality removed
Install the Cloud Client from npm:
$ npm install --save @ionic/cloudCopy the distribution file into your project (you can delete the lib/ionic-platform-web-client directory):
$ cp node_modules/@ionic/cloud/dist/bundle/ionic.cloud.min.js www/libInclude it in index.html (delete the existing ionic-platform-web-client include and leave cordova.js commented out):
<script src="lib/ionic-cloud.min.js"></script>With the new config system, you now have to manually supply the config. In app.js, fill in your app id (and gcm key if you’re using push). Don’t forget to change the module names from ionic.service.core, ionic.serve.push, etc. to just ionic.cloud. As for your .io-config.json file, we recommend deleting it. It is no longer necessary.
angular.module('my-app', ['ionic', 'ionic.cloud'])
.config(function($ionicCloudProvider) {
$ionicCloudProvider.init({
"core": {
"app_id": "APP_ID"
},
"push": {
"sender_id": "GCM_PROJECT_NUMBER"
}
});
})In an attempt to make things much easier for the majority of developers, some breaking changes were made for Ionic User. Instead of having a single User class that has everything, we've enforced a single reference to the current user and made it seem more like a model. The User class uses a service class underneath the hood that manages the single reference, making it easier on you.
Removed methods:
-
current()-$ionicUserwill now always be a reference to the current user, whether that user is anonymous, authenticated, etc. -
resetPassword()- The password reset flow has changed. See the docs. -
isAuthenticated()- Use$ionicAuth.isAuthenticated()to see if the current user is authenticated -
isFresh()- Just use the property$ionicUser.fresh, which is a boolean -
isDirty()- This method basically let you know if a save failed. Just utilize the promise returned from$ionicUser.save() -
self()- Just useload()without passing an ID.
The load(id), save(), and delete() methods all exist on $ionicUser and all update the $ionicUser reference. They no longer "return" values in the success handler.
- The last two parameters of
loginhave been swapped (options is now last so that it may be excluded, because options are optional). For example, instead oflogin('basic', {'remember': true}, details), it'slogin('basic', details, {'remember': true}) -
login()no longer resolves with the user reference.$ionicUserwill always be the active user. - The
'remember': trueoption is now the default. You can pass{'remember': false}if you want the user session to persist in session storage instead of local storage.
- We are removing development push (dev_push). We felt it only really brought confusion when setting up push. Our docs will only support setting up native push notifications.
- We removed
onRegister,onNotification, andonErrorfrom the push configuration. Going forward, the event emitter should be used. See the docs. -
gcm_keyis nowsender_idand is set in the push configuration. See the docs. -
$ionicPushActionwas removed -
$ionicPush.getPushPlugin()was removed - use$ionicPush.plugin -
$ionicPush.getPayload(notification)was removed - usenotification.payload.
Here’s how you can subscribe to events with the event emitter:
$ionicEventEmitter.on('push:notification', function(data) {
console.log(data.message);
});$ionicPush.register now uses a promise, not a callback (to be consistent). Here's how to register and save a token:
$ionicPush.register().then(function(token) {
return $ionicPush.saveToken(token);
}).then( ... );- Update
ionic-plugin-deployto 0.6.0 or later (make sure thecordova.jsinclude is uncommented in yourindex.html) -
$ionicDeploy.update()was removed - We felt it was harmful to have the download, extraction, and redirection process all in one method as it is a poor app experience. The deploy steps must now be done manually at the times you determine best for your app. See the docs. -
$ionicDeploy.watch()/$ionicDeploy.unwatch()removed - if you want to spam us you can make your own polling loop. =) -
$ionicDeploy.getVersions()was renamed to$ionicDeploy.getSnapshots() -
$ionicDeploy.deleteVersion()was renamed to$ionicDeploy.deleteSnapshot() -
$ionicDeploy.setChannel(tag)was removed - just set the$ionicDeploy.channelproperty. See the docs.
Because we switched to using standard Promise objects, the progress notification must be done a way other than a third callback of the then function. $ionicDeploy.download() and $ionicDeploy.extract() take an option for an onProgress callback. See the docs.