Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>UPDATE: from iOS 8, we cannot retrieve the serial number of our iDevice.</strong></p> <p>To retrieve iphone serial number from Monotouch, you can use this technic:</p> <ol> <li>Create a static library .a from XCode that have a function to get serial number</li> <li>In MonoDevelop, create a binding project to bind you .a library into C# classes/functions (<a href="http://docs.xamarin.com/guides/ios/advanced_topics/binding_objective-c_libraries" rel="nofollow">http://docs.xamarin.com/guides/ios/advanced_topics/binding_objective-c_libraries</a>)</li> <li>In your application, you call this binding library (in step 2).</li> </ol> <hr> <p>For detail:</p> <p>STEP 1. In my library.a, I have a class DeviceInfo, here is the implementation to get Serial number</p> <pre><code>#import "DeviceInfo.h" #import &lt;dlfcn.h&gt; #import &lt;mach/port.h&gt; #import &lt;mach/kern_return.h&gt; @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 &amp;&amp; IOServiceGetMatchingService &amp;&amp; IORegistryEntryCreateCFProperty &amp;&amp; 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 </code></pre> <p>STEP 2. In ApiDefinition.cs of my Binding Library project in Monotouch, I add this binding:</p> <pre><code>[BaseType (typeof (NSObject))] public interface DeviceInfo { [Export ("serialNumber")] NSString GetSerialNumber (); } </code></pre> <p>STEP 3. In my application, I import Reference to Binding library project in step 2, then add</p> <p>using MyBindingProject;</p> <p>...</p> <pre><code>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); } </code></pre> <p>Hope that helps. Don't hesitate if you have any question.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload