There is a "cancel" button that comes by default with UIActivityViewController
. How can I call a method when that button is pressed?
I have written this code to share the audio file.
NSURL* outURL;
UIActivityViewController *controller;
if (&UIActivityTypeAirDrop != NULL) {
controller.excludedActivityTypes = @[UIActivityTypeAirDrop];
for (int i=0;i<[arrayselecturls count];i++) {
str_SongsselectName=[[arrayselecturls objectAtIndex:i] objectForKey:@"Song"];
NSString* ext = [TSLibraryImport extensionForAssetURL:[[arrayselecturls objectAtIndex:i] objectForKey:@"SongURl"]];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
outURL = [[NSURL fileURLWithPath:[documentsDirectory stringByAppendingPathComponent:[[arrayselecturls objectAtIndex:i] objectForKey:@"Song"]]] URLByAppendingPathExtension:ext];
NSString *str_selectfilename=[NSString stringWithFormat:@"%@.mp3",str_SongsselectName];
// NSURL *url = outURL;
// NSLog(@"url is %@",url);
NSArray *objectsToShare = [NSArray arrayWithObjects:outURL,str_selectfilename, nil];
// objectsToShare = @[outURL];
controller = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
// Exclude all activities except AirDrop.
NSArray *excludedActivities = @[UIActivityTypePostToTwitter, UIActivityTypePostToFacebook,
UIActivityTypePostToWeibo,
UIActivityTypeMessage, UIActivityTypeMail,
UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo];
controller.excludedActivityTypes = excludedActivities;
}
[self presentViewController:controller animated:YES completion:nil];
}
else{
UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:@"Sorry" message:@"Your device has no Airdrop!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[Alert show];
}
oooooop! I got the solution.This solution is working fine for me.
This is the handling function.
upto here