Updated 26 October 2021
Sometimes we need to share the local file or from url . for this we need to follow some steps.
here I have taken PDF file which has to share .
1: If the file is pre loaded then access their file path by giving their name ex:abc.pdf
1 2 |
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"Heading1.PDF"]; NSString *str = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error]; |
after this we can share .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
- (IBAction)share:(id)sender { NSData *pdfData = [NSData dataWithContentsOfFile:filepath]; NSArray *activityItems = [NSArray arrayWithObjects: pdfData, 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]; } } |
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.