From 77b46896a43c6c3d5f9ce8ae85bfa84084993cce Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Tue, 4 Jul 2023 17:26:51 -0700 Subject: [PATCH] fix: Various ObjC/template cleanups (#1354) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Some minor Objective C cleanups * fix: Minor Xcode project file restructuring * fix: ability to add to resources group (#3) --------- Co-authored-by: エリス --- CordovaLib/Classes/Public/CDVAppDelegate.m | 23 ++---- CordovaLib/Classes/Public/CDVViewController.m | 34 -------- CordovaLib/include/Cordova/CDVAppDelegate.h | 8 +- lib/create.js | 8 +- .../project.pbxproj | 44 ++++------ .../{Classes => }/AppDelegate.h | 11 +-- .../{Classes => }/AppDelegate.m | 10 +-- .../Classes/MainViewController.m | 80 ------------------- .../{Classes => }/MainViewController.h | 8 -- .../__PROJECT_NAME__/MainViewController.m | 30 +++++++ .../{Classes => }/MainViewController.xib | 0 templates/project/__PROJECT_NAME__/main.m | 17 ++-- 12 files changed, 71 insertions(+), 202 deletions(-) rename templates/project/__PROJECT_NAME__/{Classes => }/AppDelegate.h (76%) rename templates/project/__PROJECT_NAME__/{Classes => }/AppDelegate.m (78%) delete mode 100644 templates/project/__PROJECT_NAME__/Classes/MainViewController.m rename templates/project/__PROJECT_NAME__/{Classes => }/MainViewController.h (83%) create mode 100644 templates/project/__PROJECT_NAME__/MainViewController.m rename templates/project/__PROJECT_NAME__/{Classes => }/MainViewController.xib (100%) diff --git a/CordovaLib/Classes/Public/CDVAppDelegate.m b/CordovaLib/Classes/Public/CDVAppDelegate.m index 8792e2005..a77fd2b4d 100644 --- a/CordovaLib/Classes/Public/CDVAppDelegate.m +++ b/CordovaLib/Classes/Public/CDVAppDelegate.m @@ -23,18 +23,19 @@ @implementation CDVAppDelegate @synthesize window, viewController; -- (id)init +- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - self = [super init]; - return self; -} +#if DEBUG + NSLog(@"Apache Cordova iOS platform version %@ is starting.", CDV_VERSION); +#endif -#pragma mark UIApplicationDelegate implementation + return YES; +} /** * 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 +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { CGRect screenBounds = [[UIScreen mainScreen] bounds]; @@ -60,7 +61,7 @@ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(N } // 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 +// only valid if Info.plist specifies a protocol to handle - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options { if (!url) { @@ -86,12 +87,4 @@ - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDiction return YES; } -- (UIInterfaceOrientationMask)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; -} - @end diff --git a/CordovaLib/Classes/Public/CDVViewController.m b/CordovaLib/Classes/Public/CDVViewController.m index 9302dc2b7..dd8ba165e 100644 --- a/CordovaLib/Classes/Public/CDVViewController.m +++ b/CordovaLib/Classes/Public/CDVViewController.m @@ -80,9 +80,6 @@ - (void)__init self.supportedOrientations = [self parseInterfaceOrientations: [[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"]]; - [self printVersion]; - [self printMultitaskingInfo]; - [self printPlatformVersionWarning]; self.initialized = YES; } } @@ -108,37 +105,6 @@ - (id)init return self; } -- (void)printVersion -{ - NSLog(@"Apache Cordova native platform version %@ is starting.", CDV_VERSION); -} - -- (void)printPlatformVersionWarning -{ - if (!IsAtLeastiOSVersion(@"8.0")) { - NSLog(@"CRITICAL: For Cordova 4.0.0 and above, you will need to upgrade to at least iOS 8.0 or greater. Your current version of iOS is %@.", - [[UIDevice currentDevice] systemVersion] - ); - } -} - -- (void)printMultitaskingInfo -{ - UIDevice* device = [UIDevice currentDevice]; - BOOL backgroundSupported = NO; - - if ([device respondsToSelector:@selector(isMultitaskingSupported)]) { - backgroundSupported = device.multitaskingSupported; - } - - NSNumber* exitsOnSuspend = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIApplicationExitsOnSuspend"]; - if (exitsOnSuspend == nil) { // if it's missing, it should be NO (i.e. multi-tasking on by default) - exitsOnSuspend = [NSNumber numberWithBool:NO]; - } - - NSLog(@"Multi-tasking -> Device: %@, App: %@", (backgroundSupported ? @"YES" : @"NO"), (![exitsOnSuspend intValue]) ? @"YES" : @"NO"); -} - -(NSString*)configFilePath{ NSString* path = self.configFile ?: @"config.xml"; diff --git a/CordovaLib/include/Cordova/CDVAppDelegate.h b/CordovaLib/include/Cordova/CDVAppDelegate.h index cce9c3421..e2cd85d8d 100644 --- a/CordovaLib/include/Cordova/CDVAppDelegate.h +++ b/CordovaLib/include/Cordova/CDVAppDelegate.h @@ -17,12 +17,12 @@ under the License. */ -#import +#import #import -@interface CDVAppDelegate : NSObject {} +@interface CDVAppDelegate : UIResponder -@property (nonatomic, strong) IBOutlet UIWindow* window; -@property (nonatomic, strong) IBOutlet CDVViewController* viewController; +@property (nullable, nonatomic, strong) IBOutlet UIWindow* window; +@property (nullable, nonatomic, strong) IBOutlet CDVViewController* viewController; @end diff --git a/lib/create.js b/lib/create.js index 9aefb6ace..7a15ee84d 100755 --- a/lib/create.js +++ b/lib/create.js @@ -175,10 +175,10 @@ class ProjectCreator { '__PROJECT_NAME__.xcworkspace/contents.xcworkspacedata', '__PROJECT_NAME__.xcworkspace/xcshareddata/xcschemes/__PROJECT_NAME__.xcscheme', '__PROJECT_NAME__.xcodeproj/project.pbxproj', - '__PROJECT_NAME__/Classes/AppDelegate.h', - '__PROJECT_NAME__/Classes/AppDelegate.m', - '__PROJECT_NAME__/Classes/MainViewController.h', - '__PROJECT_NAME__/Classes/MainViewController.m', + '__PROJECT_NAME__/AppDelegate.h', + '__PROJECT_NAME__/AppDelegate.m', + '__PROJECT_NAME__/MainViewController.h', + '__PROJECT_NAME__/MainViewController.m', '__PROJECT_NAME__/main.m', '__PROJECT_NAME__/__PROJECT_NAME__-Info.plist', '__PROJECT_NAME__/__PROJECT_NAME__-Prefix.pch' diff --git a/templates/project/__PROJECT_NAME__.xcodeproj/project.pbxproj b/templates/project/__PROJECT_NAME__.xcodeproj/project.pbxproj index d01241ee7..068e81f8f 100755 --- a/templates/project/__PROJECT_NAME__.xcodeproj/project.pbxproj +++ b/templates/project/__PROJECT_NAME__.xcodeproj/project.pbxproj @@ -58,7 +58,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 0207DA571B56EA530066E2B4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = "__PROJECT_NAME__/Assets.xcassets"; sourceTree = SOURCE_ROOT; }; + 0207DA571B56EA530066E2B4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; sourceTree = ""; }; 1D3623240D0F684500981E51 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 1D3623250D0F684500981E51 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 1D6058910D05DD3D006BFB54 /* __PROJECT_NAME__.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "__PROJECT_NAME__.app"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -72,8 +72,8 @@ 3047A5101AB8059700498E2A /* build-release.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = "build-release.xcconfig"; path = "cordova/build-release.xcconfig"; sourceTree = SOURCE_ROOT; }; 3047A5111AB8059700498E2A /* build.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = build.xcconfig; path = cordova/build.xcconfig; sourceTree = SOURCE_ROOT; }; 32CA4F630368D1EE00C91783 /* __PROJECT_NAME__-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "__PROJECT_NAME__-Prefix.pch"; sourceTree = ""; }; - 6AFF5BF81D6E424B00AB3073 /* CDVLaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = CDVLaunchScreen.storyboard; path = "__PROJECT_NAME__/CDVLaunchScreen.storyboard"; sourceTree = SOURCE_ROOT; }; - 8D1107310486CEB800E47090 /* __PROJECT_NAME__-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "__PROJECT_NAME__-Info.plist"; path = "__PROJECT_NAME__/__PROJECT_NAME__-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = SOURCE_ROOT; }; + 6AFF5BF81D6E424B00AB3073 /* CDVLaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = CDVLaunchScreen.storyboard; sourceTree = ""; }; + 8D1107310486CEB800E47090 /* __PROJECT_NAME__-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "__PROJECT_NAME__-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = ""; }; EB87FDF31871DA8E0020F90C /* www */ = {isa = PBXFileReference; lastKnownFileType = folder; name = www; path = ../../www; sourceTree = ""; }; EB87FDF41871DAF40020F90C /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = config.xml; path = ../../config.xml; sourceTree = ""; }; ED33DF2A687741AEAF9F8254 /* Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Bridging-Header.h"; sourceTree = ""; }; @@ -92,19 +92,6 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 080E96DDFE201D6D7F000001 /* Classes */ = { - isa = PBXGroup; - children = ( - 302D95EE14D2391D003F00A1 /* MainViewController.h */, - 302D95EF14D2391D003F00A1 /* MainViewController.m */, - 302D95F014D2391D003F00A1 /* MainViewController.xib */, - 1D3623240D0F684500981E51 /* AppDelegate.h */, - 1D3623250D0F684500981E51 /* AppDelegate.m */, - ); - name = Classes; - path = "__PROJECT_NAME__/Classes"; - sourceTree = SOURCE_ROOT; - }; 19C28FACFE9D520D11CA2CBB /* Products */ = { isa = PBXGroup; children = ( @@ -117,12 +104,12 @@ isa = PBXGroup; children = ( EB87FDF41871DAF40020F90C /* config.xml */, + 3047A50E1AB8057F00498E2A /* config */, EB87FDF31871DA8E0020F90C /* www */, EB87FDF11871DA420020F90C /* Staging */, 301BF52D109A57CC0062928A /* CordovaLib/CordovaLib.xcodeproj */, - 080E96DDFE201D6D7F000001 /* Classes */, + 29B97315FDCFA39411CA2CEA /* __PROJECT_NAME__ */, 307C750510C5A3420062BCA9 /* Plugins */, - 29B97315FDCFA39411CA2CEA /* Other Sources */, 29B97317FDCFA39411CA2CEA /* Resources */, 29B97323FDCFA39411CA2CEA /* Frameworks */, 19C28FACFE9D520D11CA2CBB /* Products */, @@ -130,25 +117,28 @@ name = CustomTemplate; sourceTree = ""; }; - 29B97315FDCFA39411CA2CEA /* Other Sources */ = { + 29B97315FDCFA39411CA2CEA /* __PROJECT_NAME__ */ = { isa = PBXGroup; children = ( + 8D1107310486CEB800E47090 /* __PROJECT_NAME__-Info.plist */, 32CA4F630368D1EE00C91783 /* __PROJECT_NAME__-Prefix.pch */, - 29B97316FDCFA39411CA2CEA /* main.m */, + 6AFF5BF81D6E424B00AB3073 /* CDVLaunchScreen.storyboard */, + 0207DA571B56EA530066E2B4 /* Assets.xcassets */, ED33DF2A687741AEAF9F8254 /* Bridging-Header.h */, + 302D95EE14D2391D003F00A1 /* MainViewController.h */, + 302D95EF14D2391D003F00A1 /* MainViewController.m */, + 302D95F014D2391D003F00A1 /* MainViewController.xib */, + 1D3623240D0F684500981E51 /* AppDelegate.h */, + 1D3623250D0F684500981E51 /* AppDelegate.m */, + 29B97316FDCFA39411CA2CEA /* main.m */, ); - name = "Other Sources"; + name = "__PROJECT_NAME__"; path = "__PROJECT_NAME__"; sourceTree = ""; }; 29B97317FDCFA39411CA2CEA /* Resources */ = { isa = PBXGroup; - children = ( - 0207DA571B56EA530066E2B4 /* Assets.xcassets */, - 3047A50E1AB8057F00498E2A /* config */, - 8D1107310486CEB800E47090 /* __PROJECT_NAME__-Info.plist */, - 6AFF5BF81D6E424B00AB3073 /* CDVLaunchScreen.storyboard */, - ); + children = (); name = Resources; path = "__PROJECT_NAME__/Resources"; sourceTree = ""; diff --git a/templates/project/__PROJECT_NAME__/Classes/AppDelegate.h b/templates/project/__PROJECT_NAME__/AppDelegate.h similarity index 76% rename from templates/project/__PROJECT_NAME__/Classes/AppDelegate.h rename to templates/project/__PROJECT_NAME__/AppDelegate.h index 2f72442a8..8c27551c5 100644 --- a/templates/project/__PROJECT_NAME__/Classes/AppDelegate.h +++ b/templates/project/__PROJECT_NAME__/AppDelegate.h @@ -17,17 +17,8 @@ under the License. */ -// -// AppDelegate.h -// __PROJECT_NAME__ -// -// Created by ___FULLUSERNAME___ on ___DATE___. -// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. -// - -#import #import -@interface AppDelegate : CDVAppDelegate {} +@interface AppDelegate : CDVAppDelegate @end diff --git a/templates/project/__PROJECT_NAME__/Classes/AppDelegate.m b/templates/project/__PROJECT_NAME__/AppDelegate.m similarity index 78% rename from templates/project/__PROJECT_NAME__/Classes/AppDelegate.m rename to templates/project/__PROJECT_NAME__/AppDelegate.m index f936ce3b2..3d2b6ffd4 100644 --- a/templates/project/__PROJECT_NAME__/Classes/AppDelegate.m +++ b/templates/project/__PROJECT_NAME__/AppDelegate.m @@ -17,20 +17,12 @@ Licensed to the Apache Software Foundation (ASF) under one under the License. */ -// -// AppDelegate.m -// __PROJECT_NAME__ -// -// Created by ___FULLUSERNAME___ on ___DATE___. -// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. -// - #import "AppDelegate.h" #import "MainViewController.h" @implementation AppDelegate -- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.viewController = [[MainViewController alloc] init]; return [super application:application didFinishLaunchingWithOptions:launchOptions]; diff --git a/templates/project/__PROJECT_NAME__/Classes/MainViewController.m b/templates/project/__PROJECT_NAME__/Classes/MainViewController.m deleted file mode 100644 index dcb15d974..000000000 --- a/templates/project/__PROJECT_NAME__/Classes/MainViewController.m +++ /dev/null @@ -1,80 +0,0 @@ -/* - 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. - */ - -// -// MainViewController.h -// __PROJECT_NAME__ -// -// Created by ___FULLUSERNAME___ on ___DATE___. -// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. -// - -#import "MainViewController.h" - -@implementation MainViewController - -- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil -{ - self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; - if (self) { - // Uncomment to override the CDVCommandDelegate used - // _commandDelegate = [[MainCommandDelegate alloc] initWithViewController:self]; - // Uncomment to override the CDVCommandQueue used - // _commandQueue = [[MainCommandQueue alloc] initWithViewController:self]; - } - return self; -} - -- (id)init -{ - self = [super init]; - if (self) { - // Uncomment to override the CDVCommandDelegate used - // _commandDelegate = [[MainCommandDelegate alloc] initWithViewController:self]; - // Uncomment to override the CDVCommandQueue used - // _commandQueue = [[MainCommandQueue alloc] initWithViewController:self]; - } - return self; -} - -- (void)didReceiveMemoryWarning -{ - // Releases the view if it doesn't have a superview. - [super didReceiveMemoryWarning]; - - // Release any cached data, images, etc that aren't in use. -} - -#pragma mark View lifecycle - -- (void)viewWillAppear:(BOOL)animated -{ - // View defaults to full size. If you want to customize the view's size, or its subviews (e.g. webView), - // you can do so here. - - [super viewWillAppear:animated]; -} - -- (void)viewDidLoad -{ - [super viewDidLoad]; - [self.launchView setAlpha:1]; -} - -@end diff --git a/templates/project/__PROJECT_NAME__/Classes/MainViewController.h b/templates/project/__PROJECT_NAME__/MainViewController.h similarity index 83% rename from templates/project/__PROJECT_NAME__/Classes/MainViewController.h rename to templates/project/__PROJECT_NAME__/MainViewController.h index 009b0540c..1bbe01c2d 100644 --- a/templates/project/__PROJECT_NAME__/Classes/MainViewController.h +++ b/templates/project/__PROJECT_NAME__/MainViewController.h @@ -17,14 +17,6 @@ under the License. */ -// -// MainViewController.h -// __PROJECT_NAME__ -// -// Created by ___FULLUSERNAME___ on ___DATE___. -// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. -// - #import @interface MainViewController : CDVViewController diff --git a/templates/project/__PROJECT_NAME__/MainViewController.m b/templates/project/__PROJECT_NAME__/MainViewController.m new file mode 100644 index 000000000..b99433a08 --- /dev/null +++ b/templates/project/__PROJECT_NAME__/MainViewController.m @@ -0,0 +1,30 @@ +/* + 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 "MainViewController.h" + +@implementation MainViewController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + [self.launchView setAlpha:1]; +} + +@end diff --git a/templates/project/__PROJECT_NAME__/Classes/MainViewController.xib b/templates/project/__PROJECT_NAME__/MainViewController.xib similarity index 100% rename from templates/project/__PROJECT_NAME__/Classes/MainViewController.xib rename to templates/project/__PROJECT_NAME__/MainViewController.xib diff --git a/templates/project/__PROJECT_NAME__/main.m b/templates/project/__PROJECT_NAME__/main.m index 62e5784e5..a6bff5b61 100644 --- a/templates/project/__PROJECT_NAME__/main.m +++ b/templates/project/__PROJECT_NAME__/main.m @@ -16,20 +16,15 @@ Licensed to the Apache Software Foundation (ASF) under one specific language governing permissions and limitations under the License. */ -// -// main.m -// __PROJECT_NAME__ -// -// Created by ___FULLUSERNAME___ on ___DATE___. -// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. -// #import +#import "AppDelegate.h" -int main(int argc, char* argv[]) -{ +int main(int argc, char *argv[]) { + NSString *appDelegateClassName; @autoreleasepool { - int retVal = UIApplicationMain(argc, argv, nil, @"AppDelegate"); - return retVal; + // Setup code that might create autoreleased objects goes here. + appDelegateClassName = NSStringFromClass([AppDelegate class]); } + return UIApplicationMain(argc, argv, nil, appDelegateClassName); }