Hello Readers,
In order to share text or links from the application, you may use UIActivityViewController . This is an easy way to share from within the application.
NSString *textToShare = @"text you would like to share"
NSURL *ourAppStoreLink = @"link you would like to share";
NSArray *objectsToShare = @[textToShare, ourAppStoreLink];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
NSArray *excludeActivities = @[UIActivityTypeAirDrop,
UIActivityTypePrint,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo];
activityVC.excludedActivityTypes = excludeActivities;
// If you are sharing on iphone
if (check device type is iphone) {
[self presentViewController:activityVC animated:YES completion:^{
}];
}
//For sharing on ipad the activity controller appears as pop up
else {
// Change Rect to position Popover
UIPopoverController *controller = [[UIPopoverController alloc] initWithContentViewController:activityVC];
[controller presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.width/2, 100, 100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
0 Comment(s)