iOS游戏崩溃后,只有在iPad上的共享按钮 [英] iOS game crashes after pressing Share button only on iPad

查看:448
本文介绍了iOS游戏崩溃后,只有在iPad上的共享按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iOS游戏在按下共享按钮后崩溃。这个按钮然后给用户发送/发送预先编写的文本行和到应用程序的链接到Twitter,FB,邮件,消息等的选项。我能够复制运行iOS 8.2的所有iPad模拟器的崩溃。

My iOS game crashes after the share button is pressed. This button then gives the users the option to post/send a pre-written text line and a link to the app to Twitter, FB, Mail, Messages,etc. I am able to replicate the crash on the all iPad simulators running iOS 8.2.

这是符号化的崩溃报告: https://www.dropbox.com/s/yyo4ouniegt6s0e/dotSports.crash?dl=0

Here is the symbolicated crash report: https://www.dropbox.com/s/yyo4ouniegt6s0e/dotSports.crash?dl=0

此外:这是

*** 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;
}

以下是共享按钮的代码:

Here is the code for the share button:

-(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);

            }
        }
    }];


}

任何可能导致崩溃或如何修复崩溃?

Any thoughts to what might be causing the crash or how to remedy the crash?

谢谢!

推荐答案

您正在使用 UIAlertController 显示您的共享按钮,而不包含 UIPopoverPresentationController 。当您的应用程序在iPad上运行时,您必须使用 UIPopoverPresentationController UIPopoverPresentationController上的Apple文档

You're using a UIAlertController to display your share buttons without the inclusion of a UIPopoverPresentationController. You must use a UIPopoverPresentationController when your app is running on an iPad. Apple 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];
}

这篇关于iOS游戏崩溃后,只有在iPad上的共享按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆