Phonegap使用cordova-plugin-sim获取SIM信息 [英] Phonegap getting sim information using cordova-plugin-sim

查看:291
本文介绍了Phonegap使用cordova-plugin-sim获取SIM信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是移动开发的新手.我正在使用PhoneGap,并且想在我的应用程序中添加一项功能,以便从iOS和Android上的SIM卡中获取电话号码.我正在使用此插件:

I'm new to mobile development. I'm using PhoneGap and I want to add a feature in my app to get the phone number from the SIM card, both on iOS and Android. I'm using this plugin:

cordova-plugin-sim

我正在使用这个非常简单的索引代码来显示我可以从插件中检索到的所有信息.

I'm using this very simple index code to display whatever information I can retrieve from the plugin.

<!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="UTF-8">
            <title>SIM</title>
            <script type="text/javascript" src="cordova.js"></script>
            <script type="text/javascript">
                document.addEventListener("deviceready",onDeviceReady,false);
                function onDeviceReady(){
                    window.plugins.sim.getSimInfo(successCallback, errorCallback);
                }
                function successCallback(result) {
        document.getElementById("simInfo").innerHTML=JSON.stringify(result);
                }
                function errorCallback(error) {
        document.getElementById("simInfo").innerHTML=JSON.stringify(result);
                }
            </script>
        </head>
        <body>
            <p id="simInfo"></p>
        </body>
    </html>

这不会显示任何内容.我做错了什么还是想念什么吗?

This does not display anything. Is there anything I'm doing wrong or missing?

推荐答案

您要在iOS或Android上进行测试吗?在Android 6.0及更高版本上,您需要实施.

Are you testing on iOS or Android? On Android 6.0 and above you need to implement.

  window.plugins.sim.requestReadPermission(successCallback, errorCallback);

还要查看您的代码.在errorCallback函数中,结果将是不确定的.

Also looking at your code. In the errorCallback function, result will be undefined.

您需要更改此设置.

    function errorCallback(error) {
        document.getElementById("simInfo").innerHTML=JSON.stringify(result);
    }

对此

    function errorCallback(error) {
        document.getElementById("simInfo").innerHTML=JSON.stringify(error);
    }

这篇关于Phonegap使用cordova-plugin-sim获取SIM信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆