【问题标题】:How to fetch IOS device token using ionic?如何使用 ionic 获取 IOS 设备令牌?
【发布时间】:2017-04-13 08:29:40
【问题描述】:

离子版本 2.0 科尔多瓦 6.3.1 版 Xcode 8

已经尝试了这两个链接,但没有帮助。

http://ngcordova.com/docs/plugins/pushNotifications/

https://github.com/hollyschinsky/PushNotificationSample

正在寻找使用 ionic 获取 IOS 设备令牌的详细教程/材料。

【问题讨论】:

标签: ios cordova ionic-framework cordova-plugins hybrid-mobile-app


【解决方案1】:

要使用 Ionic 推送通知,您必须发布最新的 Ionic 版本,即 Ionic 版本 2,如果您有旧版本(低于 Ionic 版本 1),它将无法工作。

CordovaPush、CordovaPush v5 已被弃用,因此请不要使用它们。

详细了解 Ionic 2 中的推送通知请参考ionic 2 push

【讨论】:

    【解决方案2】:

    你必须使用这个plugin

    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 没有被触发
    • 实际上控件并没有进入“pushNotification.register(”本身。
    • 任何错误??您是否正确配置了您的 ios 证书以接收推送通知?不要在模拟器上检查,在设备上检查。
    • 我在 xcode 控制台中没有收到任何错误 ... pushNotification.register( .... 之后没有任何内容正在处理。而且我还启用了 xcode 推送通知,没有任何错误
    【解决方案3】:

    http://ngcordova.com/docs/plugins/pushNotifications/

    只试试这个

    我也遇到了同样的问题。

    请检查测试设备的IOS OS版本。如果是10.0或以上请做

    功能部分中 Xcode 设置的适当更改

    允许推送通知(应该勾选)。

    PFB:

    Push Notification is not working on iOS 10

    【讨论】:

    • ios 版本不是 10 或更高版本只有 8... (ngcordova.com/docs/plugins/pushNotifications) 所以我无法获得设备令牌.....所以请你建议可以做什么..
    • 设备内部无需调用注册函数。
    • 无需在设备就绪函数中注册设备
    • 您可以随意调用外部注册函数....最好在您的应用程序的父控制器中,请尝试在设备就绪功能之外调用一次并告诉我结果
    • 那么我应该只添加这个 $cordovaPush.register(iosConfig).then(function(deviceToken) {// 成功 -- 将 deviceToken 发送到服务器,并存储以备将来使用console.log("deviceToken: " + deviceToken)$http.post("server.co", {u​​ser: "Bob", tokenID: deviceToken})}, function(err) {alert("注册错误: " + err)});
    猜你喜欢
    • 1970-01-01
    • 2015-12-02
    • 1970-01-01
    • 2020-01-21
    • 1970-01-01
    • 2012-12-15
    • 2012-10-02
    • 1970-01-01
    相关资源
    最近更新 更多