Skip to content

Commit

Permalink
fix: Various ObjC/template cleanups (#1354)
Browse files Browse the repository at this point in the history
* fix: Some minor Objective C cleanups
* fix: Minor Xcode project file restructuring
* fix: ability to add to resources group (#3)

---------

Co-authored-by: エリス <[email protected]>
  • Loading branch information
dpogue and erisu authored Jul 5, 2023
1 parent ad57677 commit 77b4689
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 202 deletions.
23 changes: 8 additions & 15 deletions CordovaLib/Classes/Public/CDVAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ @implementation CDVAppDelegate

@synthesize window, viewController;

- (id)init
- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary<UIApplicationLaunchOptionsKey, id> *)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<UIApplicationLaunchOptionsKey, id> *)launchOptions
{
CGRect screenBounds = [[UIScreen mainScreen] bounds];

Expand All @@ -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<UIApplicationOpenURLOptionsKey, id> *)options
{
if (!url) {
Expand All @@ -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
34 changes: 0 additions & 34 deletions CordovaLib/Classes/Public/CDVViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ - (void)__init
self.supportedOrientations = [self parseInterfaceOrientations:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"]];

[self printVersion];
[self printMultitaskingInfo];
[self printPlatformVersionWarning];
self.initialized = YES;
}
}
Expand All @@ -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";

Expand Down
8 changes: 4 additions & 4 deletions CordovaLib/include/Cordova/CDVAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
under the License.
*/

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <Cordova/CDVViewController.h>

@interface CDVAppDelegate : NSObject <UIApplicationDelegate>{}
@interface CDVAppDelegate : UIResponder <UIApplicationDelegate>

@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
8 changes: 4 additions & 4 deletions lib/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
44 changes: 17 additions & 27 deletions templates/project/__PROJECT_NAME__.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<group>"; };
1D3623240D0F684500981E51 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
1D3623250D0F684500981E51 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
1D6058910D05DD3D006BFB54 /* __PROJECT_NAME__.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "__PROJECT_NAME__.app"; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -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 = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
EB87FDF31871DA8E0020F90C /* www */ = {isa = PBXFileReference; lastKnownFileType = folder; name = www; path = ../../www; sourceTree = "<group>"; };
EB87FDF41871DAF40020F90C /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = config.xml; path = ../../config.xml; sourceTree = "<group>"; };
ED33DF2A687741AEAF9F8254 /* Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Bridging-Header.h"; sourceTree = "<group>"; };
Expand All @@ -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 = (
Expand All @@ -117,38 +104,41 @@
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 */,
);
name = CustomTemplate;
sourceTree = "<group>";
};
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 = "<group>";
};
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 = "<group>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,8 @@
under the License.
*/

//
// AppDelegate.h
// __PROJECT_NAME__
//
// Created by ___FULLUSERNAME___ on ___DATE___.
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//

#import <Cordova/CDVViewController.h>
#import <Cordova/CDVAppDelegate.h>

@interface AppDelegate : CDVAppDelegate {}
@interface AppDelegate : CDVAppDelegate

@end
Original file line number Diff line number Diff line change
Expand Up @@ -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<UIApplicationLaunchOptionsKey, id> *)launchOptions
{
self.viewController = [[MainViewController alloc] init];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
Expand Down
80 changes: 0 additions & 80 deletions templates/project/__PROJECT_NAME__/Classes/MainViewController.m

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@
under the License.
*/

//
// MainViewController.h
// __PROJECT_NAME__
//
// Created by ___FULLUSERNAME___ on ___DATE___.
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//

#import <Cordova/CDVViewController.h>

@interface MainViewController : CDVViewController
Expand Down
30 changes: 30 additions & 0 deletions templates/project/__PROJECT_NAME__/MainViewController.m
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 77b4689

Please sign in to comment.