How to get Device Serial Number in Xamarin iOSNaveen Arumugam9yAsked Jun 30, 2017, 8:34 AM6.1kXAMLHow to get Device Serial Number in Xamarin ios?
Manikandan Murugesan9y agoPosted Jun 30, 2017, 9:09 PMUPDATE: from iOS 8, we cannot retrieve the serial number of our iDevice. To retrieve iphone serial number from Monotouch, you can use this technic: Create a static library .a from XCode that have a function to get serial number 2.In MonoDevelop, create a binding project to bind you .a library into C# classes/functions Refer the following Link : https://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/ 3. In your application, you call this binding library (in step 2).For detail: STEP 1. In my library.a, I have a class DeviceInfo, here is the implementation to get Serial number#import "DeviceInfo.h" #import #import #import @implementation DeviceInfo - (NSString *) serialNumber { NSString *serialNumber = nil; void *IOKit = dlopen("/System/Library/Frameworks/IOKit.framework/IOKit", RTLD_NOW); if (IOKit) { mach_port_t *kIOMasterPortDefault = dlsym(IOKit, "kIOMasterPortDefault"); CFMutableDictionaryRef (*IOServiceMatching)(const char *name) = dlsym(IOKit, "IOServiceMatching"); mach_port_t (*IOServiceGetMatchingService)(mach_port_t masterPort, CFDictionaryRef matching) = dlsym(IOKit, "IOServiceGetMatchingService"); CFTypeRef (*IORegistryEntryCreateCFProperty)(mach_port_t entry, CFStringRef key, CFAllocatorRef allocator, uint32_t options) = dlsym(IOKit, "IORegistryEntryCreateCFProperty"); kern_return_t (*IOObjectRelease)(mach_port_t object) = dlsym(IOKit, "IOObjectRelease"); if (kIOMasterPortDefault && IOServiceGetMatchingService && IORegistryEntryCreateCFProperty && IOObjectRelease) { mach_port_t platformExpertDevice = IOServiceGetMatchingService(*kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice")); if (platformExpertDevice) { CFTypeRef platformSerialNumber = IORegistryEntryCreateCFProperty(platformExpertDevice, CFSTR("IOPlatformSerialNumber"), kCFAllocatorDefault, 0); if (CFGetTypeID(platformSerialNumber) == CFStringGetTypeID()) { serialNumber = [NSString stringWithString:(__bridge NSString*)platformSerialNumber]; CFRelease(platformSerialNumber); } IOObjectRelease(platformExpertDevice); } } dlclose(IOKit); } return serialNumber; } @end STEP 2. In ApiDefinition.cs of my Binding Library project in Monotouch, I add this binding: [BaseType (typeof (NSObject))] public interface DeviceInfo { [Export ("serialNumber")] NSString GetSerialNumber (); } STEP 3. In my application, I import Reference to Binding library project in step 2, then add using MyBindingProject; string serialNumber = ""; try { DeviceInfo nativeDeviceInfo = new DeviceInfo (); NSString temp = nativeDeviceInfo.GetSerialNumber(); serialNumber = temp.ToString(); } catch (Exception ex) { Console.WriteLine("Cannot get serial number {0} - {1}",ex.Message, ex.StackTrace); } Vivek Kumar9y agoPosted Jun 30, 2017, 10:04 AMHave a look into the below links. http://codeworks.it/blog/?p=260 https://stackoverflow.com/questions/15036415/what-is-the-simplest-way-to-retrieve-the-device-serial-number-of-an-ios-device-u
Vivek Kumar9y agoPosted Jun 30, 2017, 10:04 AMHave a look into the below links. http://codeworks.it/blog/?p=260 https://stackoverflow.com/questions/15036415/what-is-the-simplest-way-to-retrieve-the-device-serial-number-of-an-ios-device-u
Naveen ArumugamPosted Jun 30, 2017, 10:29 PM
Manikandan MurugesanPosted Jun 30, 2017, 9:09 PM
UPDATE: from iOS 8, we cannot retrieve the serial number of our iDevice.
To retrieve iphone serial number from Monotouch, you can use this technic:
- Create a static library .a from XCode that have a function to get serial number
2.In MonoDevelop, create a binding project to bind you .a library into C# classes/functionsFor detail:
STEP 1. In my library.a, I have a class DeviceInfo, here is the implementation to get Serial number
STEP 3. In my application, I import Reference to Binding library project in step 2, then add
using MyBindingProject;
Vivek KumarPosted Jun 30, 2017, 10:04 AM