ShareKit では、モーダル ビューを表示できるように、コードで rootViewController の場所を特定する必要があります。何らかの理由で、iOS 5 でコードが失敗しています。
// Try to find the root view controller programmically
// Find the top window (that is not an alert view or other window)
UIWindow *topWindow = [[UIApplication sharedApplication] keyWindow];
if (topWindow.windowLevel != UIWindowLevelNormal)
{
NSArray *windows = [[UIApplication sharedApplication] windows];
for(topWindow in windows)
{
if (topWindow.windowLevel == UIWindowLevelNormal)
break;
}
}
UIView *rootView = [[topWindow subviews] objectAtIndex:0];
id nextResponder = [rootView nextResponder];
if ([nextResponder isKindOfClass:[UIViewController class]])
self.rootViewController = nextResponder;
else
NSAssert(NO, @"ShareKit: Could not find a root view controller. You can assign one manually by calling [[SHK currentHelper] setRootViewController:YOURROOTVIEWCONTROLLER].");
これはアサートを打っています。
代わりに、単に次のコードを使用することの何が問題になっていますか?
rootViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];
これはうまく機能しているようです。条件によっては失敗する?