Share facility
Sometimes we need to share the data to messages Box or Text editor or to social networking apps. for that,IOS provide some class that will have to use for implementing “share” facility in IOS as well as Ipad.
Here is code snippet that will work fine on both platform like IPhone and IPad.
Code snippet of method on touch event:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
- (void)shareToOther:(UITapGestureRecognizer *)recognizer { NSString *productUrl = mainCollection[@"productUrl"]; NSArray *activityItems = [NSArray arrayWithObjects: productUrl, nil]; UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil]; //if iPhone if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { [self presentViewController:activityController animated:YES completion:nil]; } //if iPad else { // Change Rect to position Popover UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:activityController]; [popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } } |
Here “productUrl” contains data like URL,Text etc .