I have two apps and I'm trying to pass the PDF file from one to another.
We will consider the two apps as App1 and App2. I'm opening App2 from App1.
So I have configured URLTypes in the info plist of App2.
On click of button 'Open App2' in the App1, I'm creating a pasteboard and assigning it with one the pdf files which is in the directory of project as below:
In App1 'openApp2' action method:
//pdf copying to pasteboard
NSString *pdfPath = [[NSBundle mainBundle] pathForResource:@"thenativescriptbook" ofType:@"pdf"];
NSURL *pdfURL = [NSURL fileURLWithPath:pdfPath];
NSData *data = [NSData dataWithContentsOfURL:pdfURL];
[[UIPasteboard generalPasteboard] setData:data forPasteboardType:(NSString *)kUTTypePDF];
//code to launch app2
NSString *customAppURL = @"Example://";
NSMutableDictionary *options;
[[UIApplication sharedApplication] openURL:[NSURL
URLWithString:customAppURL] options:options completionHandler:^(BOOL
success) {
NSLog(@"**************Launch Success*************");
}];
It is launching the App2.
Now I'm trying to get the PDF file from the pasteboard in App2 like below:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSData *data = [pasteboard dataForPasteboardType:(NSString *)kUTTypePDF];
NSURL *pdfURL = [NSURL URLWithDataRepresentation:data relativeToURL:nil];
self.pdfPath = [pdfURL path];
NSLog(@"PATH: %@",self.pdfPath);
But it is giving something wrong which I'm unable to open in any of the PDF readers.