2012-10-12 32 views
4

在iOS 6上運行應用程序時,我的應用程序不再成功自動運行。我已經更新到2.1科爾多瓦,而我在我的MainViewController.m文件下面的代碼(這是CDViewController一個子類,以與處理自轉的新iOS6的方式兼容:在iOS 6上,PhoneGap 2.1 iPad應用程序不再自動旋轉

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return [super shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
} 

// iOS 6 
- (BOOL)shouldAutorotate { 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    NSUInteger ret = 0; 

    if ([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait]) 
     ret = ret | (1 << UIInterfaceOrientationPortrait); 
    if ([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortraitUpsideDown]) 
     ret = ret | (1 << UIInterfaceOrientationPortraitUpsideDown); 
    if ([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight]) 
     ret = ret | (1 << UIInterfaceOrientationLandscapeRight); 
    if ([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft]) 
     ret = ret | (1 << UIInterfaceOrientationLandscapeLeft); 

    return ret; 
} 

回答

8

在你AppDelegate.m你需要將以下添加到didFinishLaunchingWithOptions

[self.window setRootViewController:self.viewController]; 

一旦你添加此,轉動應重新開始工作,它對於我的兩個應用程序。

+1

我把該行代碼和它的作品上** iPad的2G **有**的iOS 6.1 **和**科爾多瓦1.9.0 **。多謝! – newpatriks

4

還是太新了e得到在這個線程中投票給mattdryden的答案的能力。然而,爲了增值,請注意他的建議修復也適用於PhoneGap/Cordova 1.9

我有幾個應用程序未通過PhoneGap/Cordova 1.9 - > 2.0/2.1更新過程,並手動進行上面AppDelegate.m中提出的更改,適用於這些應用程序。

另外值得一提的是,你把這條線看起來很重要。

我最初在這之前添加了這行:return YES,它失敗了。事實證明,你需要放置之前這一行:

[self.window addSubview:self.viewController.view]; 

一件事....幫助谷歌/等。發現這個問題更快......在您需要添加此行控制檯日誌的關鍵提示如下:

應用程序窗口預計將有在應用程序啓動的最後一個根視圖控制器

添加上面提到的代碼行使這個錯誤消失...

希望這可以幫助他人看到這個問題。

1

我在iOS 6上遇到了與我的iPad應用類似的問題。因爲MainViewController未設置爲AppDelegate.m中的rootViewController,所以會發生此問題。在您的AppDelegate.m取代:

[self.window addSubview:self.viewController.view]; 

self.window.rootViewController = self.viewController; 
相關問題