diff --git a/README.md b/README.md index 0fd5c06..77622aa 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,18 @@ # DeviceInformation plugin for Phonegap # -This plugin allows you to retrieve most information about your Android devices that are available through Android's Telephony Manager and Account Manager classes from your PhoneGap application: +This plugin allows you to retrieve most information about your Android/iOS* devices that are available through Android's Telephony Manager and Account Manager classes, or iOS's CTCarrier class, from your PhoneGap application: 1. Your unique Device ID 2. Phone Number (if it is stored in your SIM card) 3. Country ISO of your phone network provider 4. Name of your network provider 5. Your SIM Card Serial number -6. Country ISO of your SIM card +6. Country ISO of your SIM card* 7. Name of your SIM card mobile operator 8. E-mail/Phone number used by apps listed in your Settings > Accounts & Sync list +*(\*limited support on iOS - phone number retrieval not permitted by approval process)* + ## Adding the Plugin to your project ## Using this plugin requires [Android PhoneGap](https://github.com/apache/incubator-cordova-android). @@ -18,15 +20,15 @@ Using this plugin requires [Android PhoneGap](https://github.com/apache/incubato If you have installed PhoneGap CLI, run the following code from the command line:
phonegap local plugin add https://github.com/vliesaputra/DeviceInformationPlugin
-Otherwise, +Otherwise, to install manually on Android: -1. To install the plugin, copy the www/deviceinformation.js file to your project's www folder and include a reference to it in your html file after phonegap.js. +1. Copy the www/deviceinformation.js file to your project's www folder and include a reference to it in your html file after phonegap.js.
     <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
     <script type="text/javascript" charset="utf-8" src="deviceinformation.js"></script>
    
-2. Create a directory within your project called "src/com/vliesaputra/cordova/plugins" and copy src/com/vliesaputra/cordova/plugins/DeviceInformation.java into it. +2. Create a directory within your project called "src/com/vliesaputra/cordova/plugins" and copy src/android/DeviceInformation.java into it. 3. In your res/xml/config.xml file add the following line:
diff --git a/plugin.xml b/plugin.xml
index a4b7b7a..f2c56c4 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -23,7 +23,7 @@
    
     
         
-        		
+        		
         
         
             
@@ -37,5 +37,19 @@
         
      
 
+    
+    
+        
+            
+                
+            
+        
+        
+        
+
+        
+        
+    
+
 
 
diff --git a/src/com/vliesaputra/cordova/plugins/DeviceInformation.java b/src/android/DeviceInformation.java
similarity index 74%
rename from src/com/vliesaputra/cordova/plugins/DeviceInformation.java
rename to src/android/DeviceInformation.java
index c6c6bcc..aee9ed1 100644
--- a/src/com/vliesaputra/cordova/plugins/DeviceInformation.java
+++ b/src/android/DeviceInformation.java
@@ -15,10 +15,10 @@ public class DeviceInformation extends CordovaPlugin {
 
     private String checkValue(String str) {
         if ((str == null) || (str.length() == 0)) {
-            return "'TM.ERROR'";
+            return "\"TM.ERROR\"";
         }
 
-        return "'" + str + "'";
+        return "\"" + str + "\"";
     }
 
     private String getAccount(AccountManager am) {
@@ -32,8 +32,8 @@ private String getAccount(AccountManager am) {
                     str += ",";
                 }
 
-                str += "account" + i + "Name: " + checkValue(accounts[i].name) + ","
-                        + "account" + i + "Type: " + checkValue(accounts[i].type);
+                str += "\"account" + i + "Name\": " + checkValue(accounts[i].name) + ","
+                        + "\"account" + i + "Type\": " + checkValue(accounts[i].type);
             }
         }
 
@@ -44,13 +44,13 @@ private String getTelephone(TelephonyManager tm) {
         String str = "";
 
         if (tm != null) {
-            str = "deviceID: " + checkValue(tm.getDeviceId()) + ","
-                    + "phoneNo: " + checkValue(tm.getLine1Number()) + ","
-                    + "netCountry: " + checkValue(tm.getNetworkCountryIso()) + ","
-                    + "netName: " + checkValue(tm.getNetworkOperatorName()) + ","
-                    + "simNo: " + checkValue(tm.getSimSerialNumber()) + ","
-                    + "simCountry: " + checkValue(tm.getSimCountryIso()) + ","
-                    + "simName: " + checkValue(tm.getSimOperatorName());
+            str = "\"deviceID\": " + checkValue(tm.getDeviceId()) + ","
+                    + "\"phoneNo\": " + checkValue(tm.getLine1Number()) + ","
+                    + "\"netCountry\": " + checkValue(tm.getNetworkCountryIso()) + ","
+                    + "\"netName\": " + checkValue(tm.getNetworkOperatorName()) + ","
+                    + "\"simNo\": " + checkValue(tm.getSimSerialNumber()) + ","
+                    + "\"simCountry\": " + checkValue(tm.getSimCountryIso()) + ","
+                    + "\"simName\": " + checkValue(tm.getSimOperatorName());
         }
 
         return str;
diff --git a/src/ios/CDVDeviceInformation.h b/src/ios/CDVDeviceInformation.h
new file mode 100644
index 0000000..f581831
--- /dev/null
+++ b/src/ios/CDVDeviceInformation.h
@@ -0,0 +1,28 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import 
+#import 
+
+@interface CDVDeviceInformation : CDVPlugin
+{}
+
+- (void)get:(CDVInvokedUrlCommand*)command;
+
+@end
diff --git a/src/ios/CDVDeviceInformation.m b/src/ios/CDVDeviceInformation.m
new file mode 100644
index 0000000..d4f7aa5
--- /dev/null
+++ b/src/ios/CDVDeviceInformation.m
@@ -0,0 +1,34 @@
+#include 
+#include 
+
+#import 
+#import "CDVDeviceInformation.h"
+#import 
+#import 
+
+@interface CDVDeviceInformation () {}
+@end
+
+@implementation CDVDeviceInformation
+
+- (void)get:(CDVInvokedUrlCommand*)command
+{
+    NSString* deviceProperties = [self deviceProperties];
+    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: deviceProperties];
+
+    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+}
+
+- (NSString*)deviceProperties
+{
+    CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
+    CTCarrier *carrier = [networkInfo subscriberCellularProvider];
+
+    NSString *scc = [carrier isoCountryCode];
+    
+    NSString *result = [NSString stringWithFormat:@"{\"simCountry\":\"%@\"}", scc ?: @""];
+
+    return result;
+}
+
+@end