通过ionic.io发送Push Notification之四

2025-11-01 22:11:07

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进行测试。

通过ionic.io发送Push Notification之四

通过ionic.io发送Push Notification之四

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢