From 48cbc5a29903c90a6e0a28c417b4a0fd3dd87f76 Mon Sep 17 00:00:00 2001 From: mrjoey Date: Sun, 17 Mar 2013 18:10:21 +0800 Subject: [PATCH 01/10] Create read.me --- iOS/MacAddress/read.me | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 iOS/MacAddress/read.me diff --git a/iOS/MacAddress/read.me b/iOS/MacAddress/read.me new file mode 100644 index 00000000..2bb14722 --- /dev/null +++ b/iOS/MacAddress/read.me @@ -0,0 +1,27 @@ + +This is a plugins to help you get the WIFI MAC address. + +The UDID API is deprecated in iOS 5. To get a unique identifier, maybe you need to turn to iPhones' MAC address instead. + + +INSTALL +========================= + +1. Drag the Macaddress.h, Macaddress.m into the "Plugins" folder in Xcode. + +2. Attach the "macaddress.js" to your HTML file, and invoke that by following command in your javascript: + +[code] +plugins.macaddress.getMacAddress(function(response){ + alert('MAC Address:'+response); + },function(errorMsg){ + alert('Error:'+errorMsg); + }); +[/code] + +Don't forget to enable the plugins in Cordova config.xml + +Add this: + + + From 6b9b58c62c05f2ff27acf1c00802780ab89d81df Mon Sep 17 00:00:00 2001 From: mrjoey Date: Sun, 17 Mar 2013 18:15:43 +0800 Subject: [PATCH 02/10] Update read.me --- iOS/MacAddress/read.me | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/iOS/MacAddress/read.me b/iOS/MacAddress/read.me index 2bb14722..f27c5616 100644 --- a/iOS/MacAddress/read.me +++ b/iOS/MacAddress/read.me @@ -1,15 +1,14 @@ - This is a plugins to help you get the WIFI MAC address. The UDID API is deprecated in iOS 5. To get a unique identifier, maybe you need to turn to iPhones' MAC address instead. -INSTALL +

INSTALL

========================= 1. Drag the Macaddress.h, Macaddress.m into the "Plugins" folder in Xcode. -2. Attach the "macaddress.js" to your HTML file, and invoke that by following command in your javascript: +2. Attach the "macaddress.js" to your www folder, and invoke that by following command in your javascript: [code] plugins.macaddress.getMacAddress(function(response){ @@ -19,9 +18,13 @@ plugins.macaddress.getMacAddress(function(response){ }); [/code] -Don't forget to enable the plugins in Cordova config.xml +3. Don't forget to enable the plugins in Cordova config.xml (for Cordova 2.3 or higher) Add this: + +or Modify the PhoneGap.plist file of your application. Under the key "Plugins" add another one with key name +Macaddress and value Macaddress. (For older version) + From 90b97b930422aa635436561c7f1a9fb033e52201 Mon Sep 17 00:00:00 2001 From: mrjoey Date: Sun, 17 Mar 2013 18:16:44 +0800 Subject: [PATCH 03/10] Create README.md --- iOS/MacAddress/README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 iOS/MacAddress/README.md diff --git a/iOS/MacAddress/README.md b/iOS/MacAddress/README.md new file mode 100644 index 00000000..004ca9b8 --- /dev/null +++ b/iOS/MacAddress/README.md @@ -0,0 +1,29 @@ +This is a plugins to help you get the WIFI MAC address. + +The UDID API is deprecated in iOS 5. To get a unique identifier, maybe you need to turn to iPhones' MAC address instead. + + +

INSTALL

+========================= + +1. Drag the Macaddress.h, Macaddress.m into the "Plugins" folder in Xcode. + +2. Attach the "macaddress.js" to your www folder, and invoke that by following command in your javascript: + +[code] +plugins.macaddress.getMacAddress(function(response){ + alert('MAC Address:'+response); + },function(errorMsg){ + alert('Error:'+errorMsg); + }); +[/code] + +3. Don't forget to enable the plugins in Cordova config.xml (for Cordova 2.3 or higher) + +Add this: + + + + +or Modify the PhoneGap.plist file of your application. Under the key "Plugins" add another one with key name +Macaddress and value Macaddress. (For older version) From 40cfaf0022fe919f78651092e8968cf34d0ac720 Mon Sep 17 00:00:00 2001 From: mrjoey Date: Sun, 17 Mar 2013 18:28:24 +0800 Subject: [PATCH 04/10] Update README.md --- iOS/MacAddress/README.md | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/iOS/MacAddress/README.md b/iOS/MacAddress/README.md index 004ca9b8..d55bb363 100644 --- a/iOS/MacAddress/README.md +++ b/iOS/MacAddress/README.md @@ -1,4 +1,8 @@ -This is a plugins to help you get the WIFI MAC address. +

MacAddress plugin for Phonegap (Cordova)

+

By Joey Wong (Huang Jun Yan) Updated for Cordova 2.4.0

+ + +This is the plugins to help you get the iOS WIFI MAC address The UDID API is deprecated in iOS 5. To get a unique identifier, maybe you need to turn to iPhones' MAC address instead. @@ -6,24 +10,29 @@ The UDID API is deprecated in iOS 5. To get a unique identifier, maybe you need

INSTALL

========================= -1. Drag the Macaddress.h, Macaddress.m into the "Plugins" folder in Xcode. +1. Drag the Macaddress.h, Macaddress.m into the "Plugins" folder in Xcode. -2. Attach the "macaddress.js" to your www folder, and invoke that by following command in your javascript: - -[code] -plugins.macaddress.getMacAddress(function(response){ - alert('MAC Address:'+response); - },function(errorMsg){ - alert('Error:'+errorMsg); - }); -[/code] +2. Attach the "macaddress.js" to your www folder -3. Don't forget to enable the plugins in Cordova config.xml (for Cordova 2.3 or higher) +3. Don't forget to enable the plugins in Cordova config.xml (for Cordova 2.3 or higher) Add this: - + +<plugin name="Macaddress" value="Macaddress" /> + + +For older version, please modify the PhoneGap.plist file of your application. Under the key "Plugins" add another one with key name +Macaddress and value Macaddress. +

How to user

+========================================== +Invoke that by following command in your javascript: -or Modify the PhoneGap.plist file of your application. Under the key "Plugins" add another one with key name -Macaddress and value Macaddress. (For older version) +
+plugins.macaddress.getMacAddress(function(response){
+                                    alert('MAC Address:'+response);
+                                  },function(errorMsg){
+                                    alert('Error:'+errorMsg);
+                                  });
+
From 9758252e17b67ffe71e8842968f24244ca1d5815 Mon Sep 17 00:00:00 2001 From: mrjoey Date: Sun, 17 Mar 2013 18:28:56 +0800 Subject: [PATCH 05/10] Create macaddress.js --- iOS/MacAddress/macaddress.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 iOS/MacAddress/macaddress.js diff --git a/iOS/MacAddress/macaddress.js b/iOS/MacAddress/macaddress.js new file mode 100644 index 00000000..ce69b823 --- /dev/null +++ b/iOS/MacAddress/macaddress.js @@ -0,0 +1,19 @@ +var Macaddress = function(){} + +Macaddress.prototype = { + getMacAddress : function(onSuccess,onError) { + cordova.exec(onSuccess, onError, 'Macaddress', 'getMacAddress', []); + }, + +}; + +Macaddress.install = function(){ + if(!window.plugins){ + window.plugins = {}; + } + + window.plugins.macaddress = new Macaddress(); + return window.plugins.macaddress; +}; + +cordova.addConstructor(Macaddress.install); From 67d412385be037d8b2ca272bc95b0b23e700791d Mon Sep 17 00:00:00 2001 From: mrjoey Date: Sun, 17 Mar 2013 18:31:30 +0800 Subject: [PATCH 06/10] Create Macaddress.h --- iOS/MacAddress/Macaddress.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 iOS/MacAddress/Macaddress.h diff --git a/iOS/MacAddress/Macaddress.h b/iOS/MacAddress/Macaddress.h new file mode 100644 index 00000000..1905d433 --- /dev/null +++ b/iOS/MacAddress/Macaddress.h @@ -0,0 +1,17 @@ +// +// Macaddress.h +// Get the Wifi Mac Address +// +// Created by Joey W.(Huang Jun Yan) on 17/3/13. +// Copyright (c) 2013 Appswood. All rights reserved. +// + +#import + +@interface Macaddress : CDVPlugin +@property(nonatomic, copy) NSString *callBackId; + +@end + + + From 6e85e7262fcb1e28dbd7e5720e0975c0de797be7 Mon Sep 17 00:00:00 2001 From: mrjoey Date: Sun, 17 Mar 2013 18:31:54 +0800 Subject: [PATCH 07/10] Create Macaddress.m --- iOS/MacAddress/Macaddress.m | 89 +++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 iOS/MacAddress/Macaddress.m diff --git a/iOS/MacAddress/Macaddress.m b/iOS/MacAddress/Macaddress.m new file mode 100644 index 00000000..cbbcd23d --- /dev/null +++ b/iOS/MacAddress/Macaddress.m @@ -0,0 +1,89 @@ +// +// Macaddress.m +// Get the Wifi Mac Address +// +// Created by Joey W.(Huang Jun Yan) on 17/3/13. +// Copyright (c) 2013 Appswood. All rights reserved. +// + +#include +#include +#include +#include + +#import "Macaddress.h" + +@implementation Macaddress + +- (void)getMacAddress:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options +{ + self.callBackId=[arguments objectAtIndex:0]; + + int mgmtInfoBase[6]; + char *msgBuffer = NULL; + size_t length; + unsigned char macAddress[6]; + struct if_msghdr *interfaceMsgStruct; + struct sockaddr_dl *socketStruct; + NSString *errorFlag = NULL; + + // Setup the management Information Base (mib) + mgmtInfoBase[0] = CTL_NET; // Request network subsystem + mgmtInfoBase[1] = AF_ROUTE; // Routing table info + mgmtInfoBase[2] = 0; + mgmtInfoBase[3] = AF_LINK; // Request link layer information + mgmtInfoBase[4] = NET_RT_IFLIST; // Request all configured interfaces + + // With all configured interfaces requested, get handle index + if ((mgmtInfoBase[5] = if_nametoindex("en0")) == 0) + errorFlag = @"if_nametoindex failure"; + else + { + // Get the size of the data available (store in len) + if (sysctl(mgmtInfoBase, 6, NULL, &length, NULL, 0) < 0) + errorFlag = @"sysctl mgmtInfoBase failure"; + else + { + // Alloc memory based on above call + if ((msgBuffer = malloc(length)) == NULL) + errorFlag = @"buffer allocation failure"; + else + { + // Get system information, store in buffer + if (sysctl(mgmtInfoBase, 6, msgBuffer, &length, NULL, 0) < 0) + errorFlag = @"sysctl msgBuffer failure"; + } + } + } + + if (errorFlag != NULL) + { + errorFlag = @"No MAC address found"; + + } + + interfaceMsgStruct = (struct if_msghdr *) msgBuffer; + + socketStruct = (struct sockaddr_dl *) (interfaceMsgStruct + 1); + + memcpy(&macAddress, socketStruct->sdl_data + socketStruct->sdl_nlen, 6); + + NSString *macAddressString = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X", + macAddress[0], macAddress[1], macAddress[2], + macAddress[3], macAddress[4], macAddress[5]]; + + free(msgBuffer); + + if([macAddressString length] > 0) + { + //NSLog(@"Mac Address: %@", macAddressString); + CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:macAddressString]; + [super writeJavascript:[result toSuccessCallbackString:self.callBackId]]; + }else { + CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:errorFlag]; + [super writeJavascript:[result toErrorCallbackString:self.callBackId]]; + } + +} + +@end From 922eaf27507397c5909f4dc9053efe08f5c11e04 Mon Sep 17 00:00:00 2001 From: mrjoey Date: Sun, 17 Mar 2013 18:35:52 +0800 Subject: [PATCH 08/10] Update read.me --- iOS/MacAddress/read.me | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/iOS/MacAddress/read.me b/iOS/MacAddress/read.me index f27c5616..62318926 100644 --- a/iOS/MacAddress/read.me +++ b/iOS/MacAddress/read.me @@ -1,30 +1,40 @@ -This is a plugins to help you get the WIFI MAC address. +MacAddress plugin for Phonegap (Cordova) +By Joey Wong (Huang Jun Yan) Updated for Cordova 2.4.0 + + +This is the plugins to help you get the iOS WIFI MAC address The UDID API is deprecated in iOS 5. To get a unique identifier, maybe you need to turn to iPhones' MAC address instead. -

INSTALL

+INSTALL ========================= -1. Drag the Macaddress.h, Macaddress.m into the "Plugins" folder in Xcode. +1. Drag the Macaddress.h, Macaddress.m into the "Plugins" folder in Xcode. + +2. Attach the "macaddress.js" to your www folder + +3. Don't forget to enable the plugins in Cordova config.xml (for Cordova 2.3 or higher) + +Add this: + + + + +For older version, please modify the PhoneGap.plist file of your application. Under the key "Plugins" add another one with key name +Macaddress and value Macaddress. + +How to use +========================================== +Get the WIFI MAC address by following script : -2. Attach the "macaddress.js" to your www folder, and invoke that by following command in your javascript: -[code] plugins.macaddress.getMacAddress(function(response){ alert('MAC Address:'+response); },function(errorMsg){ alert('Error:'+errorMsg); }); -[/code] - -3. Don't forget to enable the plugins in Cordova config.xml (for Cordova 2.3 or higher) - -Add this: - - -or Modify the PhoneGap.plist file of your application. Under the key "Plugins" add another one with key name -Macaddress and value Macaddress. (For older version) +Voila ! From f554d803f363ec4dcb626a02aafc01271f167657 Mon Sep 17 00:00:00 2001 From: mrjoey Date: Sun, 17 Mar 2013 18:36:20 +0800 Subject: [PATCH 09/10] Update README.md --- iOS/MacAddress/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/iOS/MacAddress/README.md b/iOS/MacAddress/README.md index d55bb363..c694779c 100644 --- a/iOS/MacAddress/README.md +++ b/iOS/MacAddress/README.md @@ -25,9 +25,9 @@ Add this: For older version, please modify the PhoneGap.plist file of your application. Under the key "Plugins" add another one with key name Macaddress and value Macaddress. -

How to user

+

How to use

========================================== -Invoke that by following command in your javascript: +Get the WIFI MAC address by following script :
 plugins.macaddress.getMacAddress(function(response){
@@ -36,3 +36,5 @@ plugins.macaddress.getMacAddress(function(response){
                                     alert('Error:'+errorMsg);
                                   });
 
+ +Voila !~ From 1b5fec631ed2ae04cc6759d8046fc9a9e2e6201e Mon Sep 17 00:00:00 2001 From: mrjoey Date: Sun, 17 Mar 2013 18:36:58 +0800 Subject: [PATCH 10/10] Update README.md --- iOS/MacAddress/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOS/MacAddress/README.md b/iOS/MacAddress/README.md index c694779c..a728875f 100644 --- a/iOS/MacAddress/README.md +++ b/iOS/MacAddress/README.md @@ -4,7 +4,7 @@ This is the plugins to help you get the iOS WIFI MAC address -The UDID API is deprecated in iOS 5. To get a unique identifier, maybe you need to turn to iPhones' MAC address instead. +The UDID API is deprecated in iOS 5. To get a unique identifier, maybe you need to turn to iPhones/iPad/iPod touch' MAC address instead.

INSTALL