How to get device name with iOS username using Cordova?

I am using a plugin org.apache.cordova.device

. I see it was device.name

outdated a while ago in favor device.model

. When using device plugin 0.2.12 and iOS 8.1 on iPhone 5S device.name

there is undefined

.

I still need to get the name of the user's device, for example "Jerry iPhone" so that the user can see which device is using my application. How to do this with Cordova?

+3


source to share


2 answers


The best option might be to change the Device plugin (with all the unwanted 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

      

You also need to configure 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

may be deprecated and removed from the plugin, but assigned name

is still a supported attribute as in the IOS SDK 8.1 documentation .

+4


source


The device plugin does not support the name, however there is another plugin that does:



https://github.com/becvert/cordova-plugin-device-name

0


source







All Articles