How to get Device Serial Number in Xamarin iOSNaveen Arumugam9yAsked Jun 30, 2017, 4:34 AM EDT3 answersShareLinkedInXCopy linkSave
How to get Device Serial Number in Xamarin iOSNaveen Arumugam9yAsked Jun 30, 2017, 4:34 AM EDT3 answersShareLinkedInXCopy linkSave
Manikandan MurugesanRank #300 · 8.4K reputation9y agoPosted Jun 30, 2017, 5:09 PM EDT+1UPDATE: 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); } +1Vivek KumarRank #272 · 9.3K reputation9y agoPosted Jun 30, 2017, 6:04 AM EDT0Have 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 0Naveen ArumugamRank #1,227 · 1.5K reputation9y agoPosted Jun 30, 2017, 6:29 PM EDT0Thank You0Join to answer this questionEvery answer you publish earns 20 SHARP.Create free accountSign inKnow the answer?Answer a question in the forums and earn +20 SHARP for every answer.See unanswered questionsForumsTop experts01Arun PottiAnswers in the forums20answers02Tahir AnsariAnswers in the forums5answers03Kamlesh KumarAnswers in the forums5answers04Sam HobbsAnswers in the forums4answers05Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.JoinFull leaderboard →2026DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vivek KumarRank #272 · 9.3K reputation9y agoPosted Jun 30, 2017, 6:04 AM EDT0Have 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 0
Manikandan MurugesanRank #300 · 8.4K reputationPosted Jun 30, 2017, 5:09 PM EDT
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 KumarRank #272 · 9.3K reputationPosted Jun 30, 2017, 6:04 AM EDT
Naveen ArumugamRank #1,227 · 1.5K reputationPosted Jun 30, 2017, 6:29 PM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts