I've got a UIActivityViewController that shares Text and Image on Facebook/Twitter/Email, but it only works on iOS 6+.. Is it possible to pick up the iOS version running on the device and do an IF Statement to avoid crashing in iOS 5 ? If iOS6, do the following code, else do something else...?
-(void)shareMenu
{
NSString *textToShare = @"Text that will be shared";
UIImage *imageToShare = [UIImage imageNamed:@"share_picture.png"];
NSArray *itemsToShare = [[NSArray alloc] initWithObjects:textToShare, imageToShare, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = [[NSArray alloc] initWithObjects: UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeMessage, UIActivityTypePostToWeibo, nil];
[self presentViewController:activityVC animated:YES completion:nil];
}
if( [UIActivityViewController class] ) {
NSString *textToShare = @"Text that will be shared";
UIImage *imageToShare = [UIImage imageNamed:@"share_picture.png"];
NSArray *itemsToShare = [[NSArray alloc] initWithObjects:textToShare, imageToShare, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = [[NSArray alloc] initWithObjects: UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeMessage, UIActivityTypePostToWeibo, nil];
[self presentViewController:activityVC animated:YES completion:nil];
}
Or better use
if( NSClassFromString (@"UIActivityViewController") ) {
}
Read this
There are a few ways to do this, but the simplest is probably to test for the existence of this class, e.g.
if ([UIActivityViewController class])
//iOS 6+
else
// < iOS 6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With