You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/07/12 22:36:39 UTC
[2/2] ios commit: [CB-1036] factored device info into its own plugin
[CB-1036] factored device info into its own plugin
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/commit/1f4966ac
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/tree/1f4966ac
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/diff/1f4966ac
Branch: refs/heads/master
Commit: 1f4966acc8899169f1550d72a55d35aee38e1cfd
Parents: 73d0cd0
Author: Fil Maj <ma...@gmail.com>
Authored: Wed Jul 11 16:30:36 2012 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Thu Jul 12 13:37:59 2012 -0700
----------------------------------------------------------------------
CordovaLib/Classes/CDVDevice.h | 33 +++++++
CordovaLib/Classes/CDVDevice.m | 102 ++++++++++++++++++++++
CordovaLib/Classes/CDVViewController.h | 1 -
CordovaLib/Classes/CDVViewController.m | 74 +----------------
CordovaLib/javascript/cordova.ios.js | 123 +++++++++++++++++----------
5 files changed, 213 insertions(+), 120 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/1f4966ac/CordovaLib/Classes/CDVDevice.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVDevice.h b/CordovaLib/Classes/CDVDevice.h
new file mode 100644
index 0000000..bcdf80f
--- /dev/null
+++ b/CordovaLib/Classes/CDVDevice.h
@@ -0,0 +1,33 @@
+/*
+ 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 <UIKit/UIKit.h>
+#import "CDVPlugin.h"
+
+@interface CDVDevice : CDVPlugin
+{
+}
+
++ (NSString*) cordovaVersion;
+
+- (void)getDeviceInfo:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+
+@end
+
+
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/1f4966ac/CordovaLib/Classes/CDVDevice.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVDevice.m b/CordovaLib/Classes/CDVDevice.m
new file mode 100644
index 0000000..d0c0fde
--- /dev/null
+++ b/CordovaLib/Classes/CDVDevice.m
@@ -0,0 +1,102 @@
+/*
+ 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 "CDVDevice.h"
+#import "CDVViewController.h"
+
+@interface CDVDevice () {
+}
+@end
+
+
+@implementation CDVDevice
+
+- (void)getDeviceInfo:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+ NSString* cbId = [arguments objectAtIndex:0];
+ NSDictionary *deviceProperties = [self deviceProperties];
+ NSMutableString* result = [[NSMutableString alloc] initWithFormat:@""];
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceProperties];
+
+ /* Settings.plist
+ * Read the optional Settings.plist file and push these user-defined settings down into the web application.
+ * This can be useful for supplying build-time configuration variables down to the app to change its behaviour,
+ * such as specifying Full / Lite version, or localization (English vs German, for instance).
+ */
+ // TODO: turn this into an iOS only plugin
+ NSDictionary *temp = [CDVViewController getBundlePlist:@"Settings"];
+ if ([temp respondsToSelector:@selector(JSONString)]) {
+ [result appendFormat:@"\nwindow.Settings = %@;", [temp JSONString]];
+ }
+
+ NSString* jsResult = [self.webView stringByEvaluatingJavaScriptFromString:result];
+ // if jsResult is not nil nor empty, an error
+ if (jsResult != nil && [jsResult length] > 0) {
+ NSLog(@"%@", jsResult);
+ }
+
+ [result release];
+
+ [self success:pluginResult callbackId:cbId];
+
+}
+
+- (NSDictionary*) deviceProperties
+{
+ UIDevice *device = [UIDevice currentDevice];
+ NSMutableDictionary *devProps = [NSMutableDictionary dictionaryWithCapacity:4];
+ [devProps setObject:[device model] forKey:@"platform"];
+ [devProps setObject:[device systemVersion] forKey:@"version"];
+ [devProps setObject:[device uniqueAppInstanceIdentifier] forKey:@"uuid"];
+ [devProps setObject:[device name] forKey:@"name"];
+ [devProps setObject:[[self class] cordovaVersion] forKey:@"cordova"];
+
+ NSDictionary *devReturn = [NSDictionary dictionaryWithDictionary:devProps];
+ return devReturn;
+}
+
+/**
+ Returns the current version of Cordova as read from the VERSION file
+ This only touches the filesystem once and stores the result in the class variable cdvVersion
+ */
+static NSString* cdvVersion;
++ (NSString*) cordovaVersion
+{
+#ifdef CDV_VERSION
+ cdvVersion = SYMBOL_TO_NSSTRING(CDV_VERSION);
+#else
+
+ if (cdvVersion == nil) {
+ NSBundle *mainBundle = [NSBundle mainBundle];
+ NSString *filename = [mainBundle pathForResource:@"VERSION" ofType:nil];
+ // read from the filesystem and save in the variable
+ // first, separate by new line
+ NSString* fileContents = [NSString stringWithContentsOfFile:filename encoding:NSUTF8StringEncoding error:NULL];
+ NSArray* all_lines = [fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
+ NSString* first_line = [all_lines objectAtIndex:0];
+
+ cdvVersion = [first_line retain];
+ }
+#endif
+ return cdvVersion;
+}
+
+
+@end
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/1f4966ac/CordovaLib/Classes/CDVViewController.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVViewController.h b/CordovaLib/Classes/CDVViewController.h
index 50d0e23..51fb443 100644
--- a/CordovaLib/Classes/CDVViewController.h
+++ b/CordovaLib/Classes/CDVViewController.h
@@ -48,7 +48,6 @@
@property (nonatomic, readwrite, copy) NSString* startPage;
+ (NSDictionary*) getBundlePlist:(NSString*)plistName;
-+ (NSString*) cordovaVersion;
+ (NSString*) applicationDocumentsDirectory;
- (void) dispose;
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/1f4966ac/CordovaLib/Classes/CDVViewController.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVViewController.m b/CordovaLib/Classes/CDVViewController.m
index f6e95a8..a560501 100644
--- a/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/Classes/CDVViewController.m
@@ -114,8 +114,7 @@
- (void) printDeprecationNotice
{
if (!IsAtLeastiOSVersion(@"4.2")) { // TODO: change WARNING to CRITICAL for 2.0
- NSLog(@"WARNING: For Cordova 2.0 (you are using Cordova %@), you will need to upgrade to at least iOS 4.2 or greater. Your current version of iOS is %@.",
- [CDVViewController cordovaVersion],
+ NSLog(@"WARNING: For Cordova 2.0, you will need to upgrade to at least iOS 4.2 or greater. Your current version of iOS is %@.",
[[UIDevice currentDevice] systemVersion]
);
}
@@ -452,36 +451,6 @@
*/
- (void) webViewDidFinishLoad:(UIWebView*)theWebView
{
- NSDictionary *deviceProperties = [ self deviceProperties];
- NSMutableString* result = [[NSMutableString alloc] initWithFormat:
- @"(function() { \
- try { \
- cordova.require('cordova/plugin/ios/device').setInfo(%@); \
- } catch (e) { \
- return \"Error: executing module function 'setInfo' in module 'cordova/plugin/ios/device'. Have you included the iOS version of the cordova-%@.js file?\"; \
- } \
- })()",
- [deviceProperties JSONString], [CDVViewController cordovaVersion]];
-
- /* Settings.plist
- * Read the optional Settings.plist file and push these user-defined settings down into the web application.
- * This can be useful for supplying build-time configuration variables down to the app to change its behaviour,
- * such as specifying Full / Lite version, or localization (English vs German, for instance).
- */
- // TODO: turn this into an iOS only plugin
- NSDictionary *temp = [[self class] getBundlePlist:@"Settings"];
- if ([temp respondsToSelector:@selector(JSONString)]) {
- [result appendFormat:@"\nwindow.Settings = %@;", [temp JSONString]];
- }
-
- NSString* jsResult = [theWebView stringByEvaluatingJavaScriptFromString:result];
- // if jsResult is not nil nor empty, an error
- if (jsResult != nil && [jsResult length] > 0) {
- NSLog(@"%@", jsResult);
- }
-
- [result release];
-
/*
* Hide the Top Activity THROBBER in the Battery Bar
*/
@@ -921,20 +890,6 @@ BOOL gSplashScreenShown = NO;
#pragma mark -
-- (NSDictionary*) deviceProperties
-{
- UIDevice *device = [UIDevice currentDevice];
- NSMutableDictionary *devProps = [NSMutableDictionary dictionaryWithCapacity:4];
- [devProps setObject:[device model] forKey:@"platform"];
- [devProps setObject:[device systemVersion] forKey:@"version"];
- [devProps setObject:[device uniqueAppInstanceIdentifier] forKey:@"uuid"];
- [devProps setObject:[device name] forKey:@"name"];
- [devProps setObject:[CDVViewController cordovaVersion] forKey:@"cordova"];
-
- NSDictionary *devReturn = [NSDictionary dictionaryWithDictionary:devProps];
- return devReturn;
-}
-
- (NSString*) appURLScheme
{
NSString* URLScheme = nil;
@@ -969,33 +924,6 @@ BOOL gSplashScreenShown = NO;
return temp;
}
-/**
- Returns the current version of Cordova as read from the VERSION file
- This only touches the filesystem once and stores the result in the class variable gapVersion
- */
-static NSString* cdvVersion;
-+ (NSString*) cordovaVersion
-{
-#ifdef CDV_VERSION
- cdvVersion = SYMBOL_TO_NSSTRING(CDV_VERSION);
-#else
-
- if (cdvVersion == nil) {
- NSBundle *mainBundle = [NSBundle mainBundle];
- NSString *filename = [mainBundle pathForResource:@"VERSION" ofType:nil];
- // read from the filesystem and save in the variable
- // first, separate by new line
- NSString* fileContents = [NSString stringWithContentsOfFile:filename encoding:NSUTF8StringEncoding error:NULL];
- NSArray* all_lines = [fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
- NSString* first_line = [all_lines objectAtIndex:0];
-
- cdvVersion = [first_line retain];
- }
-#endif
- return cdvVersion;
-}
-
-
#pragma mark -
#pragma mark UIApplicationDelegate impl
http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/1f4966ac/CordovaLib/javascript/cordova.ios.js
----------------------------------------------------------------------
diff --git a/CordovaLib/javascript/cordova.ios.js b/CordovaLib/javascript/cordova.ios.js
index ade59c6..67d1b88 100644
--- a/CordovaLib/javascript/cordova.ios.js
+++ b/CordovaLib/javascript/cordova.ios.js
@@ -1,6 +1,6 @@
-// commit 5647225e12e18e15aefc33b151430d9a3804d9ea
+// commit 2496c766b568d4de4d38ec6dd8432045cb476010
-// File generated at :: Fri Jun 29 2012 09:38:36 GMT-0700 (PDT)
+// File generated at :: Wed Jul 11 2012 16:04:31 GMT-0700 (PDT)
/*
Licensed to the Apache Software Foundation (ASF) under one
@@ -713,7 +713,6 @@ channel.create('onDestroy');
// Channels that must fire before "deviceready" is fired.
channel.waitForInitialization('onCordovaReady');
-channel.waitForInitialization('onCordovaInfoReady');
channel.waitForInitialization('onCordovaConnectionReady');
module.exports = channel;
@@ -848,6 +847,9 @@ module.exports = {
Coordinates: {
path: 'cordova/plugin/Coordinates'
},
+ device: {
+ path: 'cordova/plugin/device'
+ },
DirectoryEntry: {
path: 'cordova/plugin/DirectoryEntry'
},
@@ -940,6 +942,7 @@ var cordova = require('cordova'),
utils = require('cordova/utils'),
gapBridge,
createGapBridge = function() {
+
gapBridge = document.createElement("iframe");
gapBridge.setAttribute("style", "display:none;");
gapBridge.setAttribute("height","0px");
@@ -950,7 +953,7 @@ var cordova = require('cordova'),
channel = require('cordova/channel');
module.exports = function() {
- if (!channel.onCordovaInfoReady.fired) {
+ if (!channel.onCordovaReady.fired) {
utils.alert("ERROR: Attempting to call cordova.exec()" +
" before 'deviceready'. Ignoring.");
return;
@@ -1047,9 +1050,6 @@ module.exports = {
MediaError: { // exists natively, override
path: "cordova/plugin/MediaError"
},
- device: {
- path: 'cordova/plugin/ios/device'
- },
console: {
path: 'cordova/plugin/ios/console'
}
@@ -1792,7 +1792,7 @@ var utils = require('cordova/utils'),
* {boolean} isDirectory always true (readonly)
* {DOMString} name of the directory, excluding the path leading to it (readonly)
* {DOMString} fullPath the absolute full path to the directory (readonly)
- * {FileSystem} filesystem on which the directory resides (readonly)
+ * TODO: implement this!!! {FileSystem} filesystem on which the directory resides (readonly)
*/
var DirectoryEntry = function(name, fullPath) {
DirectoryEntry.__super__.constructor.apply(this, [false, true, name, fullPath]);
@@ -2517,13 +2517,12 @@ var DirectoryEntry = require('cordova/plugin/DirectoryEntry');
var FileSystem = function(name, root) {
this.name = name || null;
if (root) {
- console.log('root.name ' + name);
- console.log('root.root ' + root);
this.root = new DirectoryEntry(root.name, root.fullPath);
}
};
module.exports = FileSystem;
+
});
// file: lib/common/plugin/FileTransfer.js
@@ -4026,6 +4025,74 @@ module.exports = contacts;
});
+// file: lib/common/plugin/device.js
+define("cordova/plugin/device", function(require, exports, module) {
+var channel = require('cordova/channel'),
+ utils = require('cordova/utils'),
+ exec = require('cordova/exec');
+
+// Tell cordova channel to wait on the CordovaInfoReady event
+channel.waitForInitialization('onCordovaInfoReady');
+
+/**
+ * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the
+ * phone, etc.
+ * @constructor
+ */
+function Device() {
+ this.available = false;
+ this.platform = null;
+ this.version = null;
+ this.name = null;
+ this.uuid = null;
+ this.cordova = null;
+
+ var me = this;
+
+ channel.onCordovaReady.subscribeOnce(function() {
+ me.getInfo(function(info) {
+ me.available = true;
+ me.platform = info.platform;
+ me.version = info.version;
+ me.name = info.name;
+ me.uuid = info.uuid;
+ me.cordova = info.cordova;
+ channel.onCordovaInfoReady.fire();
+ },function(e) {
+ me.available = false;
+ utils.alert("[ERROR] Error initializing Cordova: " + e);
+ });
+ });
+}
+
+/**
+ * Get device info
+ *
+ * @param {Function} successCallback The function to call when the heading data is available
+ * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL)
+ */
+Device.prototype.getInfo = function(successCallback, errorCallback) {
+
+ // successCallback required
+ if (typeof successCallback !== "function") {
+ console.log("Device Error: successCallback is not a function");
+ return;
+ }
+
+ // errorCallback optional
+ if (errorCallback && (typeof errorCallback !== "function")) {
+ console.log("Device Error: errorCallback is not a function");
+ return;
+ }
+
+ // Get info
+ exec(successCallback, errorCallback, "Device", "getDeviceInfo", []);
+};
+
+module.exports = new Device();
+
+});
+
// file: lib/common/plugin/geolocation.js
define("cordova/plugin/geolocation", function(require, exports, module) {
var utils = require('cordova/utils'),
@@ -4482,42 +4549,6 @@ module.exports = {
};
});
-// file: lib/ios/plugin/ios/device.js
-define("cordova/plugin/ios/device", function(require, exports, module) {
-/**
- * this represents the mobile device, and provides properties for inspecting the model, version, UUID of the
- * phone, etc.
- * @constructor
- */
-var exec = require('cordova/exec'),
- utils = require('cordova/utils'),
- channel = require('cordova/channel');
-
-var Device = function() {
- this.platform = null;
- this.version = null;
- this.name = null;
- this.cordova = null;
- this.uuid = null;
-};
-
-Device.prototype.setInfo = function(info) {
- try {
- this.platform = info.platform;
- this.version = info.version;
- this.name = info.name;
- this.cordova = info.cordova;
- this.uuid = info.uuid;
- channel.onCordovaInfoReady.fire();
- } catch(e) {
- utils.alert('Error during device info setting in cordova/plugin/ios/device!');
- }
-};
-
-module.exports = new Device();
-
-});
-
// file: lib/ios/plugin/ios/nativecomm.js
define("cordova/plugin/ios/nativecomm", function(require, exports, module) {
var cordova = require('cordova');