UIActivityViewController not showing PDF option - ios

I know there are many posts on this type of thing. And I believe I have tried all of the suggestions. I have a very simple problem. I have a url to a PDF and I want to be able to "share" this to the adobe pdf reader app. To remove one of the possible issues I took the PDF I was downloading and put it into my bundle so it was local. I am on iOS 8.4. Here is the code I tried:
NSURL * url2 = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource: # "data" ofType: # "pdf"]];
//Tried with the data in the file
NSData *data2 = [NSData dataWithContentsOfURL:url2];
UIActivityViewController *act=[[UIActivityViewController alloc]initWithActivityItems:#[data2] applicationActivities:nil];
//Tried with just the URL
UIActivityViewController *act=[[UIActivityViewController alloc]initWithActivityItems:#[url2] applicationActivities:nil];
act.popoverPresentationController.barButtonItem = button;
act.popoverPresentationController.sourceView = self.view;
[self presentViewController:act animated:YES completion:nil];
return;
Neither of these show the PDF option. I of course have it installed and have run it once to make sure its registered properly. Both of these I can share to Mail and the actual file is sent fine but the only share options I get are Mail, Copy and Print. I would like to see the other options like Open in iBooks and Open in Adobe Acrobat like I get from safari.
Ideas?

Related

Error while saving JPG/PNG photo to gallery in IOS 11

I was testing our application on new device with beta iOS 11 and found an intresting error.
We are creating an image which can be saved to user gallery, using UIActivityViewController (some system share view controller):
NSMutableArray *sharingItems = [NSMutableArray new];
UIImage *screenShot = [self shareViewScreenShot];
NSString *filename = #"notImportant";
NSString *path = [NSString stringWithFormat:#"%#%#.jpg", NSTemporaryDirectory(), filename];
[UIImageJPEGRepresentation(screenShot, 1.0) writeToFile:path atomically:YES];
NSURL *pathUrl = [NSURL fileURLWithPath:path];
[sharingItems addObject:pathUrl];
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];
[self presentViewController:activityController animated:YES completion:nil];
This works fine, presenting share dialog, until user press "save image". Then I got error about not suporting this image format
2017-07-19 10:51:54.292881+0200 appName[6632:766119] Video
/private/var/mobile/Containers/Data/Application/29B8C33B-9247-45FE-B51F-A35A035019A9/tmp/notImportant.jpg
cannot be saved to the saved photos album: Error
Domain=AVFoundationErrorDomain Code=-11828 "Nie można otworzyć"
UserInfo={NSUnderlyingError=0x1c08558d0 {Error
Domain=NSOSStatusErrorDomain Code=-12847 "(null)"},
NSLocalizedFailureReason=Ten format multimediów nie jest obsługiwany.,
NSURL=file:///private/var/mobile/Containers/Data/Application/29B8C33B-9247-45FE-B51F-A35A035019A9/tmp/notImportant.jpg,
NSLocalizedDescription=Nie można otworzyć}
The same happens when I use png/UIImagePNGRepresentation.
So the questions are:
Are png/jpg supported in iOS 11?
Should I use/and how HEIF (new apple image format) for devices with os version >= 11?
NSOSStatusErrorDomain code means the property data size was not correct.
OSStatus is a type commonly used for error codes in OS X and iOS. If the magnitude of the code is less than 1 million, then the code is probably listed in MacErrors.h in the CarbonCore framework. Otherwise, it is probably a four-character code listed in the same header as the function which returned it. You can find the header of a function by command-clicking it in Xcode. The codes will most likely be listed near the top, grouped together. To convert the number to a code, use the Calculator app in Developer view to convert it to hexadecimal and convert each byte to a character.
iOS treates image as video? Is this a bug on iOS or some permission is missing.
Solution:
Add permissions that was missing in Info.plist file:
<key>NSPhotoLibraryUsageDescription</key>
<string>Application needs to access photos</string>
for iOS 11+
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Application needs to access photos</string>
Now Save Image action is working ok.

Get URL to a PDF thats not in documents directory - UIDocumentInteractionController

I have a PDF that is dynamically generated from saved core data every time, rather than stored in the documents directory as NSData self.pdfData, rendered in a UIWebView. Rather than using UIActivityController to share the PDF i'd like to use UIDocumentInteractionController to get a full range of sharing options. The issue is this only seems to be for saved PDF's in the documents directory.
NSURL *PDFUrl = [[NSBundle mainBundle] URLForResource:#"sample" withExtension:#"pdf"];
Id rather not save it to documents directory then delete it, I was hoping for something more elegant. I tried to get the URL directly from the UIWebview of the PDF using self.webView.request.mainDocumentURL however this returns about:blank
NSURL *PDFUrl = [[NSBundle mainBundle] URLForResource:#"sample" withExtension:#"pdf"]; <-----
if (PDFUrl) {
DebugLog(#"Loading document");
self.documentController = [UIDocumentInteractionController interactionControllerWithURL:PDFUrl];
[self.documentController setDelegate:self];
[self.documentController presentPreviewAnimated:YES];
}
UIDocumentInteractionController only works with a file on the local file system. This means you must save the PDF to a file before you can use UIDocumentInteractionController.
Write the PDF data to a file in the caches folder (NSCachesDirectory), get its file URL, use the UIDocumentInteractionController, and then delete the file when complete.
Or use UIActivityViewController and pass the NSData of the PDF as the activity item.

How can I open an image from file system into UIImage View

Before anyone down votes my question, I have literally looked all over stack and cannot find the answer
I am making a phonegap app which I can place an image into my filesystem
the url :
file:///Users/danielnasello/Library/Application Support/iPhone Simulator/7.0.3/Applications/75EE3563-560D-4CFD-B357-313DD559573D/Documents/Vault/1386252707450.jpg
I can then pass this url to my modal controller to present an image in the image view.
the problem is I cannot seem to find the correct way to access the image from my filesystem and display it into my image view.
my current relevant code
(self.myImage) is the string i pass from phonegap. it does contain the url string because I am logging it, so I know the url is getting passed. However, the image simply will not display.
I tried using image named from one of my library images and it works fine. I just cant seem to find the correct way to present it using file url.
NSURL *url = [NSURL URLWithString:self.myImage];
NSData *data = [NSData dataWithContentsOfURL:url];
img = [[UIImage alloc] initWithData:data];
self.imageView.image= img;
here is the code for that.
NSString *filepath=[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:#"1386252707450.jpg"];
self.imageView.image=[UIImage imageWithContentsOfFile:filepath];
this code is actually correct. It just doesn't work on simulators (shocker), you need a real device

pdf download link in ipad app not working

i have a standalone offline html application which is not meant for deployment on a server.
i have converted that html application into an ipad app.
The application has links to local pdf and excel files. I have provided links to download those file in the application. It works fine in browser.
But in ipad the links to download pdf report and excel sheet reports do not work (even if I tap on the links pdf doesn't show up.It behaves like a dead link!)
Any suggestions are highly appreciated!
For downloading pdf try following:
1) Create one button to call printTapped() method
(UIBarButtonItem is good for this here)
printTapped()
- (void)printTapped
{
NSData *pdfdata = [[NSData alloc] initWithContentsOfURL:#"try your url from where you want to download the pdf"];
//Store the Data locally as PDF File
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *docsDirectory = [paths objectAtIndex:0];
NSString *filePath = [docsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:#"%#.pdf",app.stritreejob]];
//=======//
}

Converting an iPhone IOS Video File Uploader to work with a file stored in document directory

This is my first real project. I have an app that captures several seconds of video using AVFoundation, outputs this to a file in the documents directory and lets the user preview the video before they upload it using HTTP and a PHP script on my website.
All the video capture and preview work perfectly but I am stuck on uploading the video file.
I learnt a lot from this simpleSDK video which shows how to achieve the desired effect using a video file stored in the apps main bundle.
The code from the tutorial that set up videoData ready to upload originally looked like this:
NSData *videoData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Movie" ofType:#"mov"]];
NSString *urlString = #"http://www.iphonedevnation.com/video-tutorial/upload.php";
The filename of the video file that I need to upload is always unique and generated using CFUUIDCreateString. I join this string to the path for the documents directory, add ".mov" to the end of it and save it into a text file for retrieving later.
This all works as I am able to retrieve the filename from the file and use it to preview the movie clip elsewhere in the app.
My path is in an NSString, that I have tried converting to NSURL and removing the file suffix to get it to work with the NSData *videoData.........line but it doesn't compile, I get an "No known class method for selector 'dataWithContentsOfFile:ofType.' error. I am targeting iOS 5 and using Xcode 4.3 with ARC and Storyboards.
I've been at this for best part of 5 hours now so hopefully someone can help. My code, which included tips from elsewhere on converting from a NSString to NSURL follows:
NSString *content = [[NSString alloc] initWithContentsOfFile:lastSavedTalentFilenamePath
usedEncoding:nil
error:nil];
NSLog(#"content=%#",content);
//Need to now remove the '.mov' file type identifier
NSString *shortContent= [content substringToIndex:[content length]-4];
NSLog(#"***************shortContent***************%#", shortContent);
NSURL *convertedContent = [NSURL fileURLWithPath:shortContent];
NSLog(#"***************convertedContent***********%#",convertedContent);
NSData *videoData = [NSData dataWithContentsOfFile:convertedContent ofType:#"mov"];];
There is no NSData method called dataWithContentsOfFile:ofType:
The methods available are:
+ dataWithContentsOfFile:
+ dataWithContentsOfFile:options:error:
both of which take the file location as an NSString so there's not need to convert to an NSURL

Resources