如何获取iOS用户设置设备名称与Cordova? [英] How to get iOS user-set device name with 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屋!