How to handle file upload in WKWebview? - ios

I am displaying a html page using WKWebview in Swift 5. I have an option to upload image using input file tag. When I run the app and click on upload, it prompts to select Photo library or Camera. If I select camera, app crashes since the app doesn't have permission.
How to remove camera option or properly request the permission when the user select camera?

I am not sure but you can just set key Privacy - Camera Usage Description in info.plist file with description. Web view will manage for permission and it will work. Please check and let me know if work for you.

Related

Is there a possibility to save a video to the gallery when the camera is called with a <input type="file">?

I'm trying to build a hybrid iPhone app that makes use of the html-tag for video uploads.
Camera opens when the input is clicked, users can record video and upload works fine.
I'm quite new into swift and iOS-development, therefore my question:
How can I address the video inside the native app part, to additionally store it on the phone inside the gallery? Is this possible?
You should use accept="video/mp4,video/x-m4v,video/*"
MIMEType webkit

iOS Safari file input [Take Photo] capture = Pano

On iOS Safari, and clicking to input a file with accept image/*, I get the [Take Photo] option. When I touch that I'd like the option for Pano, to be available, but it's not.
Basically I created a demo where you can upload an iOS Pano and vie it in 360. Works great, but the user has to upload a previously shot Pano, and not take one realtime.
Was hoping something like capture="pano" or accept="image/*;capture=pano" as the file input's attribute, would do the trick.
Anyone know a way this could be done, or do I need to do a dev request at Apple?

Add "Edit in Excel" or "Edit photo" extension

I checked the latest Dropbox and Excel for iOS. In Dropbox we get an edit button. On click it opens Excel's extension where you can edit the file.
After save, changes are reflected in the Dropbox file too.
I want to add such a button. Also I'd like to add such a button to images to open them in available "photo editing" apps.
How to check if file (image, xls, doc or any other) can be opened to edit?
Code so far:
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithURL:url inMode:UIDocumentPickerModeExportToService];
documentPicker.delegate = self;
documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:documentPicker animated:YES completion:nil];
Also tried changing mode to UIDocumentPickerModeMoveToService...
As per apple docs
Move a local document. The user selects an external destination. The document picker moves the document; however, you can still access the document as an external document, letting the user edit the document in place.
But I tried all four modes. Did not show excel option.
UIDocumentPickerModeImport,
UIDocumentPickerModeOpen,
UIDocumentPickerModeExportToService,
UIDocumentPickerModeMoveToService
The only way to communicate with other iOS apps "locally" is using what is called URLSchemes.
This is the documentation to use URLScheme with the MSOffice apps.
https://msdn.microsoft.com/en-us/library/office/dn911482.aspx
Answering the specific question:
How to check if file (image, xls, doc or any other) can be opened to edit?
You can use the UIApplication method called canOpenURL to check if the current device responds to a specific URLScheme and if it does, you can call the app to edit you file. The same can be applied to other apps that you want to open. You just need to see if the app have URLScheme support.
Remembering that in iOS 9 you need to add the URLs you want to call during the app life in the Info.plist. Otherwise, the canOpenURL method will always returno NO.
This code illustrates the approach. However, it is to search some navigation apps. Just like tapping a shared friend location in WhatsApp.
https://snipt.net/wallaaa/using-url-schemes/
The result:
it's 2017 and iOS 11 and it's still not possible to edit files in place.
Dropbox is using MS Office API to provide http links to download and upload changed document.
Direct edit of the file is only possible if FileProvider extension is implemented and file was opened in editor app via document picker (which grants access to the file in sandbox).
Photo editing is allowed because editor is made by Apple (Photos app).

How can I show last saved photo in Photos app iOS via "photos-redirect:" URL scheme?

When I use photos-redirect:// URL scheme it just starts Photos app.
How can I start Photos app with showing custom photo, for example, last saved?
I can't find any examples, where used photos-redirect:// URL scheme.
photos-redirect:// is the URL Scheme for Photo App. However, it is undocumented, thus you shouldn't use it.
To view / select a photo, use UIImagePickerController .

email a video in iOS

I have an app that records a video and saves it straight to the photo library on the iPhone. I want to, as soon as the user finishes recording, have the app open up in mail, with the video attached. How should I go about doing this?
I am using this basic idea: http://blog.mugunthkumar.com/coding/iphone-tutorial-in-app-email/
How do I get the file path for the video?
You could either store the video in your app and then attach that into the email before copying it to the photo library or show the user their photo library in the app via UIImagePicker - This may help or just google it ...
http://developer.apple.com/library/ios/#samplecode/MyImagePicker/Introduction/Intro.html#//apple_ref/doc/uid/DTS40010135

Resources