我正在使用 cordova 2.1.0 创建一个应用程序,但在构建过程中,我收到以下警告
找不到实例方法“-supportsOrientation:”(返回类型默认为“id”)。
这是我的 AppDelegate.m 文件 -
/*
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.
*/
//
// AppDelegate.m
//
// Created by ___FULLUSERNAME___ on ___DATE___.
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
//
#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];
self = [super init];
return self;
}
#pragma 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
{
NSURL* url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
NSString* invokeString = nil;
if (url && [url isKindOfClass:[NSURL class]]) {
invokeString = [url absoluteString];
NSLog(@"Shop launchOptions = %@", url);
}
CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window = [[UIWindow alloc] initWithFrame:screenBounds];
self.window.autoresizesSubviews = YES;
self.viewController = [[MainViewController alloc] init];
self.viewController.useSplashScreen = YES;
self.viewController.wwwFolderName = @"www";
self.viewController.startPage = @"index.html";
// self.viewController.invokeString = invokeString;
// NOTE: To control the view's frame size, override [self.viewController viewWillAppear:] in your view controller.
// check whether the current orientation is supported: if it is, keep it, rather than forcing a rotation
BOOL forceStartupRotation = YES;
UIDeviceOrientation curDevOrientation = [[UIDevice currentDevice] orientation];
if (UIDeviceOrientationUnknown == curDevOrientation) {
// UIDevice isn't firing orientation notifications yet… go look at the status bar
curDevOrientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
}
if (UIDeviceOrientationIsValidInterfaceOrientation(curDevOrientation)) {
if ([self.viewController supportsOrientation:curDevOrientation]) {
forceStartupRotation = NO;
}
}
if (forceStartupRotation) {
UIInterfaceOrientation newOrient;
if ([self.viewController supportsOrientation:UIInterfaceOrientationPortrait])
newOrient = UIInterfaceOrientationPortrait;
else if ([self.viewController supportsOrientation:UIInterfaceOrientationLandscapeLeft])
newOrient = UIInterfaceOrientationLandscapeLeft;
else if ([self.viewController supportsOrientation:UIInterfaceOrientationLandscapeRight])
newOrient = UIInterfaceOrientationLandscapeRight;
else
newOrient = UIInterfaceOrientationPortraitUpsideDown;
NSLog(@"AppDelegate forcing status bar to: %d from: %d", newOrient, curDevOrientation);
[[UIApplication sharedApplication] setStatusBarOrientation:newOrient];
}
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 Shop-Info.plist specifies a protocol to handle
- (BOOL) application:(UIApplication*)application handleOpenURL:(NSURL*)url
{
if (!url) {
return NO;
}
// calls into javascript global function 'handleOpenURL'
NSString* jsString = [NSString stringWithFormat:@"handleOpenURL(\"%@\");", url];
[self.viewController.webView stringByEvaluatingJavaScriptFromString:jsString];
// all plugins will get the notification, and their handlers will be called
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]];
return YES;
}
- (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 whats allowed (the supported orientations mask gets intersected).
NSUInteger supportedInterfaceOrientations = (1 << UIInterfaceOrientationPortrait) | (1 << UIInterfaceOrientationLandscapeLeft) | (1 << UIInterfaceOrientationLandscapeRight) | (1 << UIInterfaceOrientationPortraitUpsideDown);
return supportedInterfaceOrientations;
}
@end
我也无法运行该应用程序,日志上显示以下错误 -
2012-10-03 16:38:07.653 Shop[829:13403] Multi-tasking -> Device: YES, App: YES
2012-10-03 16:38:07.671 Shop[829:13403] -[MainViewController supportsOrientation:]: unrecognized selector sent to instance 0x7e725e0
2012-10-03 16:38:07.718 Shop[829:13403] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MainViewController supportsOrientation:]: unrecognized selector sent to instance 0x7e725e0'
*** First throw call stack:
(0x1a2022 0x207dcd6 0x1a3cbd 0x108ed0 0x108cb2 0x2dfa 0x337386 0x338274 0x347183 0x347c38 0x33b634 0x271fef5 0x176195 0xdaff2 0xd98da 0xd8d84 0xd8c9b 0x337c65 0x339626 0x290c 0x28a5 0x1)
terminate called throwing an exception(lldb)
我找不到与它相关的任何东西......