You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2015/03/13 00:10:51 UTC

ios commit: CB-8473 - Remove AppDelegate code from template (includes uncrustify style fix-ups)

Repository: cordova-ios
Updated Branches:
  refs/heads/4.0.x 205a6629e -> 0053d35b4


CB-8473 - Remove AppDelegate code from template (includes uncrustify style fix-ups)


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/0053d35b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/0053d35b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/0053d35b

Branch: refs/heads/4.0.x
Commit: 0053d35b4ab3239e6c74e1ddc628d01827e282d6
Parents: 205a662
Author: Shazron Abdullah <sh...@apache.org>
Authored: Thu Mar 12 16:10:50 2015 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Thu Mar 12 16:10:50 2015 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVAppDelegate.h             |  28 ++++
 CordovaLib/Classes/CDVAppDelegate.m             | 143 +++++++++++++++++++
 CordovaLib/CordovaLib.xcodeproj/project.pbxproj |   8 ++
 .../__PROJECT_NAME__/Classes/AppDelegate.h      |  13 +-
 .../__PROJECT_NAME__/Classes/AppDelegate.m      | 116 +--------------
 5 files changed, 183 insertions(+), 125 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/0053d35b/CordovaLib/Classes/CDVAppDelegate.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVAppDelegate.h b/CordovaLib/Classes/CDVAppDelegate.h
new file mode 100644
index 0000000..de5b518
--- /dev/null
+++ b/CordovaLib/Classes/CDVAppDelegate.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 <Foundation/Foundation.h>
+#import "CDVViewController.h"
+
+@interface CDVAppDelegate : NSObject <UIApplicationDelegate>{}
+
+@property (nonatomic, strong) IBOutlet UIWindow* window;
+@property (nonatomic, strong) IBOutlet CDVViewController* viewController;
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/0053d35b/CordovaLib/Classes/CDVAppDelegate.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVAppDelegate.m b/CordovaLib/Classes/CDVAppDelegate.m
new file mode 100644
index 0000000..ab81d7d
--- /dev/null
+++ b/CordovaLib/Classes/CDVAppDelegate.m
@@ -0,0 +1,143 @@
+/*
+ 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 "CDVAppDelegate.h"
+
+@implementation CDVAppDelegate
+
+@synthesize window, viewController;
+
+- (id)init
+{
+    /** If you need to do any extra app-specific initialization, you can do it here
+     *  -jm
+     **/
+    NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
+
+    [cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
+
+    int cacheSizeMemory = 8 * 1024 * 1024; // 8MB
+    int cacheSizeDisk = 32 * 1024 * 1024; // 32MB
+#if __has_feature(objc_arc)
+        NSURLCache* sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"];
+#else
+        NSURLCache* sharedCache = [[[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"] autorelease];
+#endif
+    [NSURLCache setSharedURLCache:sharedCache];
+
+    self = [super init];
+    return self;
+}
+
+#pragma mark UIApplicationDelegate implementation
+
+/**
+ * This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
+ */
+- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
+{
+    CGRect screenBounds = [[UIScreen mainScreen] bounds];
+
+#if __has_feature(objc_arc)
+        self.window = [[UIWindow alloc] initWithFrame:screenBounds];
+#else
+        self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
+#endif
+    self.window.autoresizesSubviews = YES;
+
+    // only set if not already set in subclass
+    if (self.viewController == nil) {
+#if __has_feature(objc_arc)
+            self.viewController = [[CDVViewController alloc] init];
+#else
+            self.viewController = [[[CDVViewController alloc] init] autorelease];
+#endif
+    }
+
+    // Set your app's start page by setting the <content src='foo.html' /> tag in config.xml.
+    // If necessary, uncomment the line below to override it.
+    // self.viewController.startPage = @"index.html";
+
+    // NOTE: To customize the view's frame size (which defaults to full screen), override
+    // [self.viewController viewWillAppear:] in your view controller.
+
+    self.window.rootViewController = self.viewController;
+    [self.window makeKeyAndVisible];
+
+    return YES;
+}
+
+// this happens while we are running ( in the background, or from within our own app )
+// only valid if 40x-Info.plist specifies a protocol to handle
+- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
+{
+    if (!url) {
+        return NO;
+    }
+
+    // all plugins will get the notification, and their handlers will be called
+    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
+
+    return YES;
+}
+
+// repost all remote and local notification using the default NSNotificationCenter so multiple plugins may respond
+- (void)            application:(UIApplication*)application
+    didReceiveLocalNotification:(UILocalNotification*)notification
+{
+    // re-post ( broadcast )
+    [[NSNotificationCenter defaultCenter] postNotificationName:CDVLocalNotification object:notification];
+}
+
+#ifndef DISABLE_PUSH_NOTIFICATIONS
+
+    - (void)                                 application:(UIApplication*)application
+        didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
+    {
+        // re-post ( broadcast )
+        NSString* token = [[[[deviceToken description]
+            stringByReplacingOccurrencesOfString:@"<" withString:@""]
+            stringByReplacingOccurrencesOfString:@">" withString:@""]
+            stringByReplacingOccurrencesOfString:@" " withString:@""];
+
+        [[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotification object:token];
+    }
+
+    - (void)                                 application:(UIApplication*)application
+        didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
+    {
+        // re-post ( broadcast )
+        [[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotificationError object:error];
+    }
+#endif
+
+- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
+{
+    // iPhone doesn't support upside down by default, while the iPad does.  Override to allow all orientations always, and let the root view controller decide what's allowed (the supported orientations mask gets intersected).
+    NSUInteger supportedInterfaceOrientations = (1 << UIInterfaceOrientationPortrait) | (1 << UIInterfaceOrientationLandscapeLeft) | (1 << UIInterfaceOrientationLandscapeRight) | (1 << UIInterfaceOrientationPortraitUpsideDown);
+
+    return supportedInterfaceOrientations;
+}
+
+- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application
+{
+    [[NSURLCache sharedURLCache] removeAllCachedResponses];
+}
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/0053d35b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
index c30a128..0c757d6 100644
--- a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
+++ b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
@@ -34,6 +34,8 @@
 		7E14B5A81705050A0032169E /* CDVTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E14B5A61705050A0032169E /* CDVTimer.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		7E14B5A91705050A0032169E /* CDVTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E14B5A71705050A0032169E /* CDVTimer.m */; };
 		7E5D94151AB23DB400F4D9EB /* CDVPlugin+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E5D94141AB23DB400F4D9EB /* CDVPlugin+Private.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		7E5D94181AB250F800F4D9EB /* CDVAppDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E5D94161AB250F800F4D9EB /* CDVAppDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
+		7E5D94191AB250F800F4D9EB /* CDVAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E5D94171AB250F800F4D9EB /* CDVAppDelegate.m */; };
 		8852C43A14B65FD800F0E735 /* CDVViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 8852C43614B65FD800F0E735 /* CDVViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
 		8852C43C14B65FD800F0E735 /* CDVViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8852C43714B65FD800F0E735 /* CDVViewController.m */; };
 		8887FD741090FBE7009987E8 /* CDVInvokedUrlCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = 8887FD341090FBE7009987E8 /* CDVInvokedUrlCommand.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -81,6 +83,8 @@
 		7E14B5A61705050A0032169E /* CDVTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVTimer.h; path = Classes/CDVTimer.h; sourceTree = "<group>"; };
 		7E14B5A71705050A0032169E /* CDVTimer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVTimer.m; path = Classes/CDVTimer.m; sourceTree = "<group>"; };
 		7E5D94141AB23DB400F4D9EB /* CDVPlugin+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "CDVPlugin+Private.h"; path = "Classes/CDVPlugin+Private.h"; sourceTree = "<group>"; };
+		7E5D94161AB250F800F4D9EB /* CDVAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVAppDelegate.h; path = Classes/CDVAppDelegate.h; sourceTree = "<group>"; };
+		7E5D94171AB250F800F4D9EB /* CDVAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVAppDelegate.m; path = Classes/CDVAppDelegate.m; sourceTree = "<group>"; };
 		8852C43614B65FD800F0E735 /* CDVViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVViewController.h; path = Classes/CDVViewController.h; sourceTree = "<group>"; };
 		8852C43714B65FD800F0E735 /* CDVViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVViewController.m; path = Classes/CDVViewController.m; sourceTree = "<group>"; };
 		8887FD341090FBE7009987E8 /* CDVInvokedUrlCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVInvokedUrlCommand.h; path = Classes/CDVInvokedUrlCommand.h; sourceTree = "<group>"; };
@@ -166,6 +170,8 @@
 				8887FD501090FBE7009987E8 /* NSData+Base64.h */,
 				8887FD511090FBE7009987E8 /* NSData+Base64.m */,
 				306ADAE21AAA73E100CAC885 /* CDVWebViewEngineProtocol.h */,
+				7E5D94161AB250F800F4D9EB /* CDVAppDelegate.h */,
+				7E5D94171AB250F800F4D9EB /* CDVAppDelegate.m */,
 			);
 			name = Public;
 			sourceTree = "<group>";
@@ -219,6 +225,7 @@
 				306ADAE61AAA73E100CAC885 /* CDVWebViewEngineProtocol.h in Headers */,
 				EB96673B16A8970A00D86CDF /* CDVUserAgentUtil.h in Headers */,
 				306ADAEA1AAA745400CAC885 /* CDVCommandQueue.h in Headers */,
+				7E5D94181AB250F800F4D9EB /* CDVAppDelegate.h in Headers */,
 				7E5D94151AB23DB400F4D9EB /* CDVPlugin+Private.h in Headers */,
 				EB6A98571A77FA430013FCDB /* NSData+Base64.h in Headers */,
 				306ADAEB1AAA747100CAC885 /* NSMutableArray+QueueAdditions.h in Headers */,
@@ -289,6 +296,7 @@
 				30E563D013E217EC00C949AA /* NSMutableArray+QueueAdditions.m in Sources */,
 				30C684821406CB38004C1A8E /* CDVWhitelist.m in Sources */,
 				30C684961407044B004C1A8E /* CDVURLProtocol.m in Sources */,
+				7E5D94191AB250F800F4D9EB /* CDVAppDelegate.m in Sources */,
 				8852C43C14B65FD800F0E735 /* CDVViewController.m in Sources */,
 				3034979E1513D56A0090E688 /* CDVLocalStorage.m in Sources */,
 				306ADAE51AAA73E100CAC885 /* CDVUIWebViewEngine.m in Sources */,

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/0053d35b/bin/templates/project/__PROJECT_NAME__/Classes/AppDelegate.h
----------------------------------------------------------------------
diff --git a/bin/templates/project/__PROJECT_NAME__/Classes/AppDelegate.h b/bin/templates/project/__PROJECT_NAME__/Classes/AppDelegate.h
index c5ecc85..2f72442 100644
--- a/bin/templates/project/__PROJECT_NAME__/Classes/AppDelegate.h
+++ b/bin/templates/project/__PROJECT_NAME__/Classes/AppDelegate.h
@@ -25,18 +25,9 @@
 //  Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
 //
 
-#import <UIKit/UIKit.h>
-
 #import <Cordova/CDVViewController.h>
+#import <Cordova/CDVAppDelegate.h>
 
-@interface AppDelegate : NSObject <UIApplicationDelegate>{}
-
-// invoke string is passed to your app on launch, this is only valid if you
-// edit __PROJECT_NAME__-Info.plist to add a protocol
-// a simple tutorial can be found here :
-// http://iphonedevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
-
-@property (nonatomic, strong) IBOutlet UIWindow* window;
-@property (nonatomic, strong) IBOutlet CDVViewController* viewController;
+@interface AppDelegate : CDVAppDelegate {}
 
 @end

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/0053d35b/bin/templates/project/__PROJECT_NAME__/Classes/AppDelegate.m
----------------------------------------------------------------------
diff --git a/bin/templates/project/__PROJECT_NAME__/Classes/AppDelegate.m b/bin/templates/project/__PROJECT_NAME__/Classes/AppDelegate.m
index 3cb3198..f936ce3 100644
--- a/bin/templates/project/__PROJECT_NAME__/Classes/AppDelegate.m
+++ b/bin/templates/project/__PROJECT_NAME__/Classes/AppDelegate.m
@@ -28,124 +28,12 @@
 #import "AppDelegate.h"
 #import "MainViewController.h"
 
-#import <Cordova/CDVPlugin.h>
-
 @implementation AppDelegate
 
-@synthesize window, viewController;
-
-- (id)init
-{
-    /** If you need to do any extra app-specific initialization, you can do it here
-     *  -jm
-     **/
-    NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
-
-    [cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
-
-    int cacheSizeMemory = 8 * 1024 * 1024; // 8MB
-    int cacheSizeDisk = 32 * 1024 * 1024; // 32MB
-#if __has_feature(objc_arc)
-        NSURLCache* sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"];
-#else
-        NSURLCache* sharedCache = [[[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"] autorelease];
-#endif
-    [NSURLCache setSharedURLCache:sharedCache];
-
-    self = [super init];
-    return self;
-}
-
-#pragma mark UIApplicationDelegate implementation
-
-/**
- * This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up)
- */
 - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
 {
-    CGRect screenBounds = [[UIScreen mainScreen] bounds];
-
-#if __has_feature(objc_arc)
-        self.window = [[UIWindow alloc] initWithFrame:screenBounds];
-#else
-        self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
-#endif
-    self.window.autoresizesSubviews = YES;
-
-#if __has_feature(objc_arc)
-        self.viewController = [[MainViewController alloc] init];
-#else
-        self.viewController = [[[MainViewController alloc] init] autorelease];
-#endif
-
-    // Set your app's start page by setting the <content src='foo.html' /> tag in config.xml.
-    // If necessary, uncomment the line below to override it.
-    // self.viewController.startPage = @"index.html";
-
-    // NOTE: To customize the view's frame size (which defaults to full screen), override
-    // [self.viewController viewWillAppear:] in your view controller.
-
-    self.window.rootViewController = self.viewController;
-    [self.window makeKeyAndVisible];
-
-    return YES;
-}
-
-// this happens while we are running ( in the background, or from within our own app )
-// only valid if __PROJECT_NAME__-Info.plist specifies a protocol to handle
-- (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation
-{
-    if (!url) {
-        return NO;
-    }
-
-    // all plugins will get the notification, and their handlers will be called
-    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
-
-    return YES;
-}
-
-// repost all remote and local notification using the default NSNotificationCenter so multiple plugins may respond
-- (void)            application:(UIApplication*)application
-    didReceiveLocalNotification:(UILocalNotification*)notification
-{
-    // re-post ( broadcast )
-    [[NSNotificationCenter defaultCenter] postNotificationName:CDVLocalNotification object:notification];
-}
-
-#ifndef DISABLE_PUSH_NOTIFICATIONS
-
-    - (void)                                 application:(UIApplication*)application
-        didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
-    {
-        // re-post ( broadcast )
-        NSString* token = [[[[deviceToken description]
-            stringByReplacingOccurrencesOfString:@"<" withString:@""]
-            stringByReplacingOccurrencesOfString:@">" withString:@""]
-            stringByReplacingOccurrencesOfString:@" " withString:@""];
-
-        [[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotification object:token];
-    }
-
-    - (void)                                 application:(UIApplication*)application
-        didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
-    {
-        // re-post ( broadcast )
-        [[NSNotificationCenter defaultCenter] postNotificationName:CDVRemoteNotificationError object:error];
-    }
-#endif
-
-- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
-{
-    // iPhone doesn't support upside down by default, while the iPad does.  Override to allow all orientations always, and let the root view controller decide what's allowed (the supported orientations mask gets intersected).
-    NSUInteger supportedInterfaceOrientations = (1 << UIInterfaceOrientationPortrait) | (1 << UIInterfaceOrientationLandscapeLeft) | (1 << UIInterfaceOrientationLandscapeRight) | (1 << UIInterfaceOrientationPortraitUpsideDown);
-
-    return supportedInterfaceOrientations;
-}
-
-- (void)applicationDidReceiveMemoryWarning:(UIApplication*)application
-{
-    [[NSURLCache sharedURLCache] removeAllCachedResponses];
+    self.viewController = [[MainViewController alloc] init];
+    return [super application:application didFinishLaunchingWithOptions:launchOptions];
 }
 
 @end


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org