未找到实例方法'-supportsOrientation'

时间:2012-10-03 11:16:38

标签: ios cordova xcode4

我正在使用cordova 2.1.0创建一个应用程序,但在构建过程中,我收到以下警告

实例方法'-supportsOrientation:'not found(返回类型默认为'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) 

我无法找到与之相关的任何内容......

1 个答案:

答案 0 :(得分:0)

我发现的工作是从架构和有效的架构列表中删除armv6并添加armv7s

在Xcode中:

  • 项目导航&gt;您的项目&gt; “构建设置”选项卡
  • 在搜索框中,搜索“架构”
  • 选择:标准armv7 armv7s

  • 项目导航&gt; CordovaLib.xcodeproj&gt; “构建设置”选项卡

  • 在搜索框中,搜索“架构”
  • 选择:标准armv7 armv7s
  • 在搜索框中搜索“有效架构”
  • 删除armv6
  • 添加armv7s