Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityViewController crashing, NSCFConstantString _beforeActivity unrecognized selector sent to instance

I'm trying to add the new iOS 6 sharing functionality to my app using the UIActivityViewController. I've got some text that I want to share and if they choose Email I want to automatically set the Subject of the email as well.

NSArray *activityItems = @[resultString];
NSLog(@"items=%@", activityItems);

NSArray *acitivities = @[UIActivityTypeMail, UIActivityTypeMessage, UIActivityTypePrint, UIActivityTypePostToFacebook, UIActivityTypeCopyToPasteboard];

UIActivityViewController *activityController =
    [[UIActivityViewController alloc] initWithActivityItems:activityItems
                                      applicationActivities:activities];

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    self.popover = [[UIPopoverController alloc] initWithContentViewController:activityController];
    // the line above is where the error happens.
    [self.popover presentPopoverFromBarButtonItem:self.emailResultsButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
    [self presentViewController:activityController
                       animated:YES
                     completion:nil];
}

Here is the output of the code including the error message:

[694:907] items=(
    "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas porttitor accumsan mi eu mollis. Fusce condimentum dictum lectus, eu ultrices urna vulputate eu."
)
[694:907] -[__NSCFConstantString _beforeActivity]: unrecognized selector sent to instance 0x3ad971c8
[694:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString _beforeActivity]: unrecognized selector sent to instance 0x3ad971c8'
*** First throw call stack:
(0x35add2a3 0x37a1497f 0x35ae0e07 0x35adf531 0x35a36f68 0x361dc7a3 0x361dc52d 0x36067595 0x36434d31 0x3642fe07 0x2990b 0x361330ad 0x36133135 0x361330ad 0x3613305f 0x3613303d 0x361328f3 0x36132de9 0x3605b5f9 0x36048809 0x36048123 0x37bd15a3 0x37bd11d3 0x35ab2173 0x35ab2117 0x35ab0f99 0x35a23ebd 0x35a23d49 0x37bd02eb 0x3609c301 0x1ef9d 0x1ef30)
libc++abi.dylib: terminate called throwing an exception

I'm running this on an iPad 2 with iOS6. Any ideas?

EDIT: It appears if I do not supply the activities array then everything seems to work fine. Still narrowing down the problem.

like image 311
Kenny Wyland Avatar asked Oct 26 '12 18:10

Kenny Wyland


People also ask

What is a uiactivityviewcontroller?

A standard view controller that connects the application to a number of standard services such as social networks, SMS, etc. The UIActivityViewController allows the application user to easily share data between the current application and services. A number of services such as social networks, email, and SMS are provided by the OS.

Why isn’t “copy to book tracker” displayed in uiactivityviewcontroller?

Note: If you don’t see “Copy to Book Tracker” displayed in UIActivityViewController after tapping the attached file in your email, you may need to edit the order of supported apps by scrolling to the end of the list, selecting More, and moving “Copy to BookTracker” to the top of the list.

What is beginappearancetransition in UIViewController?

With BeginAppearanceTransition (Boolean, Boolean), tells child UIViewController s that their child views have just appeared or disappeared. The array of child UIViewController objects that should be searched to determine if they are the unwind segue destination.

Can You airdrop with uiactivityviewcontroller?

UIActivityViewController has been around since iOS6, but despite how useful it is, it’s often under-appreciated. Perhaps one of the best options is the ability to AirDrop. If you have two devices — or better yet, a friend with the Book Tracker app installed — you can test AirDropping books!


1 Answers

The exception says it all: You're passing in an array of strings:

NSArray *acitivities = @[UIActivityTypeMail, UIActivityTypeMessage, UIActivityTypePrint, UIActivityTypePostToFacebook, UIActivityTypeCopyToPasteboard];

The documentation says the method expects a list of UIActivity objects:

applicationActivities

An array of UIActivity objects representing the custom services that your application supports. This parameter may be nil.

Note that this is for custom activities; e.g. if you want to offer your own DropBox integration in addition to existing services.

EDIT: As for the activity types, they only appear to be used in UIActivity.activityType, UIActivityItemProvider.activityType, UIActivityViewController.excludedActivityTypes, and -[UIActivityItemSource activityViewController:itemForActivityType:].

like image 197
tc. Avatar answered Oct 04 '22 02:10

tc.