如何使用Ionic获取iOS设备令牌?

3

请查看此链接:https://dev59.com/DZbfa4cB1Zd3GeqPqjkw - Anbu.Karthik
你可以使用全局变量“device”来访问设备ID等属性。 device.uuid - Satish Mavani
3个回答

1

iOS版本不是10或以上,只有8......如果我使用相同的代码,控制根本不会进入这里"document.addEventListener("deviceready", function(){ " t(http://ngcordova.com/docs/plugins/pushNotifications/),所以我无法获取设备令牌......因此,请建议可以做什么。 - Aniruddh
不需要在设备准备好函数内调用注册函数。 - Abhishek Srivastava
在“设备准备就绪”函数中不需要注册设备。 - Abhishek Srivastava
即使如此,我仍然遇到以下错误:1. 未捕获的错误:[$injector:unpr] 未知提供者:$cordovaPushProvider <- $cordovaPush(…) 2. 未捕获的引用错误:$cordovaPush未定义(…)。我已经添加了插件cordova plugin add https://github.com/phonegap-build/PushPlugin.git,但仍然面临这个问题。 - Aniruddh
请使用更新命令更新您的推送插件。有时config.xml文件不会根据新安装的插件进行更新。 - Abhishek Srivastava
显示剩余4条评论

1
你需要使用这个 插件
if ( device.platform == 'iOS'){
pushNotification.register(
        tokenHandler,
        errorHandler,
        {
            "badge":"true",
            "sound":"true",
            "alert":"true",
            "ecb":"onNotificationAPN"
        });
    }
}

在设备就绪事件之后编写此代码。
function errorHandler(error) {
    alert(error);
}

这是错误回调函数。
function tokenHandler(result){
    // Your iOS push server needs to know the token before it can push to this device
    // here is where you might want to send it the token for later use.
    //alert('device token = ' + result);
    sDeviceId = result ;
}

在 sDeviceId 中,您可以获取设备令牌。

当我在设备上运行代码时,函数errorHandler或tokenHandler没有被触发。 - Aniruddh
事实上,控制并没有进入“pushNotification.register()”本身。 - Aniruddh
你是否正确配置了iOS证书以接收推送通知? 不要在模拟器上检查,应该在设备上检查。 - Anuj.T
我在Xcode控制台中没有收到任何错误...在pushNotification.register(....)之后没有任何处理。而且,我也已经成功开启了Xcode推送通知,没有出现任何错误。 - Aniruddh

0
要使用Ionic推送通知,您必须拥有最新发布的Ionic版本即Ionic版本2。如果您使用旧版本(低于Ionic版本1),则无法正常工作。
CordovaPush, CordovaPush v5已经过时,请不要使用它们。
有关Ionic 2中推送通知的详细了解,请参考ionic 2 push

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接