如何获取iOS用户设置设备名称与Cordova? [英] How to get iOS user-set device name with Cordova?

查看:279
本文介绍了如何获取iOS用户设置设备名称与Cordova?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 org.apache.cordova.device 插件。我看到 device.name 已被弃用 a而赞成 device.model 。当在iPhone 5S上使用设备插件0.2.12和iOS 8.1时, device.name undefined

I'm using the org.apache.cordova.device plugin. I see that device.name has been deprecated a while back in favor of device.model. When using device plugin 0.2.12 and iOS 8.1 on iPhone 5S, device.name is undefined.

我仍然需要获取用户的设备名称,例如Jerry's iPhone,以便用户可以看到他们的设备正在使用我的应用程序。

I still need to get the user's device name, like "Jerry's iPhone", so that the user can see which of their devices are using my app. How to do that with Cordova?

推荐答案

您最好的选择可能是修改设备插件(所有不良后果)。我可以通过在./cordova/platforms/ios/[project name] /Plugins/org.apache.cordova中的 deviceProperties 中添加以下行来获取设备名称。 device / CDVDevice.m:

Your best bet might be modifying the Device plugin (with all the undesired consequences). I was able to get the device name by adding the following line to deviceProperties in ./cordova/platforms/ios/[project name]/Plugins/org.apache.cordova.device/CDVDevice.m:

- (NSDictionary*)deviceProperties
{
    UIDevice* device = [UIDevice currentDevice];
    NSMutableDictionary* devProps = [NSMutableDictionary dictionaryWithCapacity:4];
    [devProps setObject:[device name] forKey:@"name"];    // <------------- new line

需要调整./cordova/plugins/org.apache.cordova.device/www/device.js中的相应Javascript对象:

You also need to adjust the corresponding Javascript object in ./cordova/plugins/org.apache.cordova.device/www/device.js:

 channel.onCordovaReady.subscribe(function() {
    me.getInfo(function(info) {
        me.name = info.name;             // <---------- new line

device.name 已弃用并从插件中删除,但分配的名称仍是iOS SDK 8.1中支持的属性文档

device.name may have been deprecated and removed from the plugin, but the assigned name is still a supported attribute as of the iOS SDK 8.1 documentation.

这篇关于如何获取iOS用户设置设备名称与Cordova?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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