-1

First off, I'm a newbie in programming, please bear with me guys. I'm working on an iOS game built using the Cocos2Dx engine in Xcode. The game has a Share button which is used to share scores. The button seems to work with the iPhone but crashes all the time on an iPad. Xcode points to this line each time it crashes on the iPad:

int retVal = UIApplicationMain(argc, argv, nil, @"AppController");

I figured this issue came about after I changed another piece of code to implement the functionality of the share button. The code which I changed is in the function below.

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

  //  [self.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);

            }
        }
    }];

The line I changed is this one (which is in the function above):

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

I would like to know why that line works on the iPhone devices but not on the iPad? And how could I resolve it to work on the iPad as well? Maybe an alternative piece code?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
KaybeSir
  • 11
  • 1
  • Xcode 5? If so, add an exception breakpoint to see the line where the error occurs (respectively the closest line in the call stack for which there's source code available). – CodeSmile Dec 10 '14 at 12:45
  • Hi. I'm using Xcode 6. I did try using an exception break point and it seems to take me to that same line detailed in the question. Jerome's suggestion below has enlightened me a bit. I don't know if you may know any solution along the lines of displaying the UIActivityViewController inside a UIPopoverController? – KaybeSir Dec 10 '14 at 15:32

1 Answers1

0

Take a look at UIActivity activityViewController being presented modally on iPad instead of in popover

On iPad an UIActivityViewController must be displayed inside a UIPopoverController

Community
  • 1
  • 1
Jerome Diaz
  • 1,746
  • 8
  • 15
  • Hi Jerome. Thanks for that suggestion. It's helped me find more information into resolving the issue. So I've come up with a temporary solution to at least allow the code to work on the iPhone. So now my app checks if the code is running on the iPhone first. I'm still looking to find out how to display the UIActivityViewController in a UIPopoverController. As a newbie for me the fun is in digging around to find pieces of code which will work. I'll welcome any further suggestions. Thanks – KaybeSir Dec 10 '14 at 15:24