Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Various ObjC/template cleanups #1354

Merged
merged 3 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Some minor Objective C cleanups
  • Loading branch information
dpogue committed Jun 29, 2023
commit ebc194fc9ab2aa7f4d995a225d6ed7826446d39b
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
11 changes: 1 addition & 10 deletions templates/project/__PROJECT_NAME__/Classes/AppDelegate.h
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
10 changes: 1 addition & 9 deletions templates/project/__PROJECT_NAME__/Classes/AppDelegate.m
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
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
50 changes: 0 additions & 50 deletions templates/project/__PROJECT_NAME__/Classes/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,10 @@ Licensed to the Apache Software Foundation (ASF) under one
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];
Expand Down
17 changes: 6 additions & 11 deletions templates/project/__PROJECT_NAME__/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 <UIKit/UIKit.h>
#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);
}