通过ionic.io发送Push Notification之四
1、iOS
2、Android
1、创建app,步骤与受限模式类似。
ionic start myApp
cd myApp
ionic add ionic-platform-web-client
ionic plugin add phonegap-plugin-push --variable SENDER_ID="GCM_PROJECT_NUMBER"
替换为自己的Project Number。
2、我在安装push plugin时,出现了以下错误:
Updated the hooks directory to have execute permissions
Installing "phonegap-plugin-push" for ios
Plugin doesn't support this project's cordova-ios version. cordova-ios: 3.8.0, failed version requirement: >=4.1.0
Skipping 'phonegap-plugin-push' for ios
Using this version of Cordova with older version of cordova-ios is being deprecated. Consider upgrading to cordova-ios@4.0.0 or newer.
Saving plugin to package.json file
我的解决方法是,运行:
cordova platform update ios
再重新安装plugin。
3、链接到ionic.io:
ionic io init
4、禁止受限模式push:
ionic config set dev_push false
5、增加代码(与受限模式非常类似,只是增加了在ionic.io中保存token):
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
var push = new Ionic.Push({
"debug": true
});
push.register(function(token) {
console.log("Device token:",token.token);
push.saveToken(token); // persist the token in the Ionic Platform
});
});
})
6、可以使用ionic.io的Dashboard或者Google Chrome的Postman进行测试。

