问题:
- 关于Registration ID第一次获取不到,可以用setTimeout延迟后获取。
- ios开发环境能收到通知消息,生产模式接收不到通知消息。
- ios发布到app store上,下下来的app仍然获取不到id。使用xcode连接iPhone安装的app,就能获取到id。
版本:
- lonic3
- angular cli:6.0.7
- node:8.11.1
关于如何下载jpush插件及极光推送文档:
具体代码:
- 业务需求:登录时获取到Registration ID后关联此账户,然后把ID发送给后台。
- 首先 初始化jpush
- app.component.ts
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
/* 验证是否在 app 中 */
if (platform.is('cordova')) {
/* 更新APP */
this.hotCode.hotCodeUpdate();
/* 极光推送 */
jpush.init();
jpush.setDebugMode(false);
}
});
- 在登录界面获取到token后发送id
- login.ts
public doLogin = () => {
this.ajax.loadData({
uri: 'login',
method: 'post',
title: '登录请求',
data: this.loginForm.value,
//afterFn: afterFn
}).subscribe(res => {
this.msg.hideLoader();
if (res.status === 1) {
const crypt_token: string = res.payload.crypt_token;
const zhiwei: string = res.payload.zhiwei;
this.storage.set('zhiwei', zhiwei);
this.storage.set('crypt_token', this.stringCode.encode(crypt_token)).then(() => {
this.events.publish('login', res);
this.viewCtrl.dismiss();
//获取token后,获取极光推送id,然后发送id
setTimeout(() => {
this.jpush.getRegistrationID().then(res => {
this.registrationID = res;
// alert('login时获取id:'+this.registrationID);
this.getJiGuangID(this.registrationID);
});
}, 1000);
});
}
});
}
}
/**
* @description 发送极光id
* @private
* @memberof LoginPage
*/
public getJiGuangID = (id) => {
this.ajax.loadData({
uri: `jiguang_info/` + id,
method: 'get',
title: '发送极光推送 registrationID '
}).subscribe(res => {
// alert('login时发送id成功。')
})
}
问题解决:
- ios开发环境能收到通知消息,生产模式接收不到通知消息。
解决方案:
- xcode上找到 TARGET -> Capabilities -> Push Notification 选项点开
- xcode上找到 TARGET -> Build Setting -> Code Signing Identity -> Code Signing Entitlements *****Entitle-release.plist 看看有没有 aps-environment 字段,没有补上(关键是这一步,加上字段就成功了!)
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
</dict>
</plist>
注意点:
- 取不到 token 就取不到 registrationID。(这个坑了我好久。。。)
- 关于Registration ID第一次获取不到,可以用setTimeout延迟后获取。
- Registration ID还是获取不到,请检查证书及各个id是否对应。