2015-05-02 64 views
-2

按下分享按鈕後,我的iOS遊戲崩潰。這個按鈕可以讓用戶選擇發送/發送預先寫好的文本行和鏈接到應用程序到Twitter,FB,郵件,消息等。我能夠在運行iOS 8.2的所有iPad模擬器上覆制崩潰。僅在iPad上按Share(分享)按鈕後iOS遊戲崩潰

這裏是symbolicated崩潰報告:https://www.dropbox.com/s/yyo4ouniegt6s0e/dotSports.crash?dl=0

除了:服用產生碰撞的行動時,這是在Xcode輸出框。

*** Terminating app due to uncaught exception 'NSGenericException', reason: 'UIPopoverPresentationController (<_UIAlertControllerActionSheetRegularPresentationController: 0x7a863100>) should have a non-nil sourceView or barButtonItem set before the presentation occurs.' 
*** First throw call stack: 
(
    0 CoreFoundation      0x04980466 __exceptionPreprocess + 182 
    1 libobjc.A.dylib      0x03caea97 objc_exception_throw + 44 
    2 UIKit        0x02564517 -[UIPopoverPresentationController presentationTransitionWillBegin] + 3086 
    3 UIKit        0x01e63f48 __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke + 1666 
    4 UIKit        0x01e624eb __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 186 
    5 UIKit        0x01e9642b __40+[UIViewController _scheduleTransition:]_block_invoke + 18 
    6 UIKit        0x01d5b946 ___afterCACommitHandler_block_invoke + 15 
    7 UIKit        0x01d5b8f1 _applyBlockToCFArrayCopiedToStack + 415 
    8 UIKit        0x01d5b706 _afterCACommitHandler + 545 
    9 CoreFoundation      0x048a318e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30 
    10 CoreFoundation      0x048a30d0 __CFRunLoopDoObservers + 400 
    11 CoreFoundation      0x04898b0a __CFRunLoopRun + 1226 
    12 CoreFoundation      0x0489837b CFRunLoopRunSpecific + 443 
    13 CoreFoundation      0x048981ab CFRunLoopRunInMode + 123 
    14 GraphicsServices     0x0524d2c1 GSEventRunModal + 192 
    15 GraphicsServices     0x0524d0fe GSEventRun + 104 
    16 UIKit        0x01d319b6 UIApplicationMain + 1526 
    17 Gem Dots copy      0x00213896 main + 134 
    18 libdyld.dylib      0x04365ac9 start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

下面是它崩潰的代碼:

#import <UIKit/UIKit.h> 

int main(int argc, char *argv[]) { 

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 
    int retVal = UIApplicationMain(argc, argv, nil, @"AppController"); 
    [pool release]; 
    return retVal; 
} 

下面是分享按鈕代碼:

-(void) displayShare:(NSString*)strText imageIdx:(int)nIdx URL:(NSString*)strURL 
{ 
    UIActivityViewController *activityView; 

    if(nIdx >= 0) 
    { 
     NSString* str = [NSString stringWithFormat:@"new-arc-%d-ipad.png", nIdx+1]; 
     UIImage* image = [UIImage imageNamed:str]; 
     activityView = [[UIActivityViewController alloc] initWithActivityItems:@[strText, image, [NSURL URLWithString:strURL]] applicationActivities:nil]; 
    } 
    else 
     activityView = [[UIActivityViewController alloc] initWithActivityItems:@[strText, [NSURL URLWithString:strURL]] applicationActivities:nil]; 

    activityView.excludedActivityTypes = @[UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypePrint]; 

    // [viewController presentViewController:activityView animated:YES completion:nil]; 
    [window.rootViewController presentViewController:activityView animated:YES completion:nil]; 

    [activityView setCompletionHandler:^(NSString *activityType, BOOL completed) { 
     NSLog(@"completed dialog - activity: %@ - finished flag: %d", activityType, completed); 

     if(completed) 
     { 
      if([activityType isEqualToString: @"com.apple.UIKit.activity.PostToFacebook"]) 
      { 
       g_bArchiveMark[19] = true; 
       AppSettings::setArchieveInfo(19); 
      } 
      else if([activityType isEqualToString: @"com.apple.UIKit.activity.PostToTwitter"]) 
      { 
       g_bArchiveMark[20] = true; 
       AppSettings::setArchieveInfo(20); 

      } 
     } 
    }]; 


} 

任何想法,以什麼可能會導致崩潰或如何彌補崩潰?

謝謝!

+0

請更新您的問題,包括崩潰報告和任何相關的代碼。 –

+0

你有沒有使用activityviewcontroller –

回答

0

您正在使用UIAlertController來顯示分享按鈕,而不包含UIPopoverPresentationController。當您的應用在iPad上運行時,您必須使用UIPopoverPresentationControllerApple Docs on UIPopoverPresentationController

例如:

-(IBAction)myButton:(id)sender { 
    UIAlertController *shareController= [UIAlertController 
           alertControllerWithTitle:nil 
           message:nil 
           preferredStyle:UIAlertControllerStyleActionSheet]; 
    UIAlertAction *shareServiceButton = [UIAlertAction 
            actionWithTitle:@"Share Service" 
            style:UIAlertActionStyleDefault 
            handler:^(UIAlertAction *action) 
            { 
             // Share something 
            }]; 
    [shareController addAction:shareServiceButton]; 

    // User on iPad 
    UIPopoverPresentationController *popoverController; 
    popoverController = shareController.popoverPresentationController; 
    popoverController.sourceView = self.view; 
    popoverController.sourceRect = self.myButton.frame; 
    popoverController.permittedArrowDirections = UIPopoverArrowDirectionAny; 

    [self presentViewController:shareController animated:YES completion:nil]; 
} 
+0

謝謝丹尼爾的迴應。我是新來的編碼和購買這個源代碼。我已經用分享按鈕被按下時執行的確切代碼更新了我的原始帖子。你能給我更多的指導嗎? –