Single Image picker in Flutter on iOS without permission - ios

According to those SO questions: UIImagePickerController not asking for permission and No permission to pick a photo from the photo library
If you want to select one image on iOS, you don't have to ask for permission to do it as the app doesn't actually access the gallery.
However, I can't find a way of doing it Flutter. Packages like ImagePicker always ask for permission.
Has anyone succeeded in picking an image in Flutter on iOS without asking for permission?

From Apple documentation:
PHPickerViewController is a new picker that replaces UIImagePickerController. Its user interface matches that of the Photos app, supports search and multiple selection of photos and videos, and provides fluid zooming of content. Because the system manages its life cycle in a separate process, it’s private by default. The user doesn’t need to explicitly authorize your app to select photos, which results in a simpler and more streamlined user experience.
This library uses PHPickerViewController as seen here

The old UIImagePickerController allowed it on older iOS'es, but it has been deprecated, since iOS 14.
The Flutter ImagePicker plugin uses the PHPicker in the iOS code, as I checked for their code on Github, and it allows you to pick an image from the user without requesting permissions. I recommend highly to use that plugin.

Try file_picker it should work for you as it supports all the platform including IOS and Mac supporting various types of file type, you can specify your custom file types also limiting your file selections as well as you can pick files from cloud (GDrive, Dropbox, iCloud)...
First of all add the latest file_picker as a dependency in your pubspec.yaml file.
Import this dependency in file wherever you want to use and then you are good to go...
for picking single file use this code:
FilePickerResult? result = await FilePicker.platform.pickFiles();
if (result != null) {
File file = File(result.files.single.path);
} else {
// User canceled the picker
}
files with extension filter:
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['jpg', 'pdf', 'doc'],
);
You can find detailed usage Here
you can find the documentation Here

Related

How to choose and open available navigation app from Xamarin iOS?

I have the following code to open Navigation App from one of the button click in my content page.
var location = new Location(Convert.ToDouble(jobItem.Latitude), Convert.ToDouble(jobItem.Longitude));
var options = new MapLaunchOptions { NavigationMode = NavigationMode.Driving };
await Map.OpenAsync(location, options);
There are Google Maps and Waze in my android phone, so the code above did show the selection panel and let user to choose which app to use which is no issue. However, when this meet iOS, it straight away open Apple Maps without any selection even though there are 3 navigation apps in the iPhone. I have tried to research to deal with the default navigation app setting on iOS but unfortunately iOS didn't provide any single option to set the app as default unlike android. What else I can do?
You could use the Xamarin.Essentials: Launcher NuGet package.
You'd need to modify the code to look something like the below pseudocode
var supportsWaze = await Launcher.CanOpenAsync("whateverTheWazeUriSchemeIs://");
var supportsGoogleMaps = await Launcher.CanOpenAsync("whateverTheUriSchemeIs://");
You'd then need to give the user some sort of UI for them to select a mapping app based upon these boolean(s) being true. I'd use an ActionSheet
Then you can use the await Launcher.OpenAsync method to open the correct URI based on whatever choice the user made. You could offer them the option to remember this choice for later as well.
iOS wont allow you to override the OS default apps, but within your own app you can choose how other applications are launched. The Google applications are a good example of this.

How can I check whether the photo library is empty?

I am creating a button to let the user choose an image from their photo library, and I would like to hide this button if there are no images in the user’s photo library.
BOOL stillImagesAvailable = [[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary] containsObject:(NSString *)kUTTypeImage];
if (!stillImagesAvailable) {
// Hide button
return;
}
stillImagesAvailable = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
if (!stillImagesAvailable) {
// Hide button
return;
}
// Show button
+[UIImagePickerController isSourceTypeAvailable:] is documented to return NO if there are no photos in the library, but I'm seeing it return YES in this case on iOS 11 running on the simulator. Am I using this method wrong, or is the documentation incorrect, or am I running into a bug?
Is there another good way to detect whether there are any images in the user’s photo library?
UIImagePickerController doesn't expose this information. That class generally doesn't provide information about the user's photo library, merely some user-selected contents thereof. (The documentation you cite appears to be incorrect — I'd recommend filing a bug against the documentation for them to change it.)
Aside: The "user-selected" part is important in iOS 11 and later: the image picker runs in a separate process, meaning your app gets access only to the picked assets, meaning you don't have to ask the user for blanket read/write access to the Photos library through privacy settings.) Keep that privacy stuff in mind for further down in this answer, though...
If you need to learn about the contents of the user's Photos library, use the Photos framework. If specifically you want to know whether the library is "empty", you'll need to define what "empty" means for your app. No assets saved in the local library through iOS? No assets synced onto the device through iTunes? What if I have no assets, but I do have some empty albums?
Assuming one possible answer to those questions (no local or synced assets, don't care about albums), here's some (untested) code that should get your answer:
- (BOOL)isPhotoLibraryEmpty {
PHFetchOptions *options = [PHFetchOptions new];
options.includeAssetSourceTypes = PHAssetSourceTypeUserLibrary | PHAssetSourceTypeiTunesSynced;
PHFetchResult *results = [PHAsset fetchAssetsWithOptions:options];
return results.count == 0;
}
However, if this would be your app's only use of the Photos framework, it might be wiser to think about whether it's worthwhile to preemptively check for an empty library. If you use the Photos framework at all, your app needs blanket read/write access to the Photos library through the iOS privacy settings (that is, you provide a NSPhotoLibraryUsageDescription in your info.plist, and iOS prompts the user for permission the first time you call any Photos API).
For example, if all you're using the Photos framework for is to check for an empty library so you know whether to disable a "pick a photo" button in your UI... getting that deep into the privacy/permissions system probably isn't worth it. (Now you're actively interrupting them with a privacy prompt instead of passively disabling a button.) It's probably better to just let the user do whatever your UI does for invoking the image picker, and let UIImagePickerController show an appropriate screen if the library is empty (which it does).

How to display photo library permissions dialog in Cordova?

Hi we are developing an IBM MobileFirst Platform-based Hybrid Application. In our application we are accessing user gallery (to upload photos). for this in iPhone we need to ask the user permission explicitly, to ask user permission in iPhone we need to display dialog box. Here my question is the dialog box which we are going to show to the user is custom dialog box or is there any native feature built-in in MobileFirst, or with the help of any cordova plugin?
You can use requestCameraRollAuthorization() in cordova-diagnostic-plugin to request native iOS permission to access the user photos:
cordova.plugins.diagnostic.requestCameraRollAuthorization(function(granted){
console.log("Authorization request for camera roll was " + (granted ? "granted" : "denied"));
}, function(error){
console.error(error);
});
MobileFirst does not handle any permissions for you - it is not that kind of a framework. This really relates to the Cordova layer in your app, which access the photo library.
You need to display a dialog box asking the user whether or not does s/he allow for the access to access the photo library. You can use WL.SimpleDialog for this purpose, for example.
Read more here:
http://docs.phonegap.com/en/3.3.0/guide_appdev_privacy_index.md.html#Privacy%20Guide
Cordova Camera Plugin in IOS 9
perhaps to check if there is access given, create also a Cordova plug-in that will check for it using native code: Determine if the access to photo library is set or not - PHPhotoLibrary (iOS 8)

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).

Application Would You Like to Use Your Current Location! using ALAssetsLibrary

My application only gets image and it's metadata from ios device using ALAssetsLibrary.
When application starts loading images list ios warning is shown..
"Application" Would Like to Use Your Current Location.
This allows access to location information in photos and videos.
Is there way to fix program code in such way that this warning not to be shown? (not by using Setting->General....)
I think user doesn't understand why application during picking the image asks about location.
If you need the metadata info, using assetslibrary is your only option. Using Alassetslibrary means that the user grants permission to location services. The simple reason for that is that the photos metadata might contain location/gps data.
Cheers,
Hendrik
UPDATED: It will not request access permission in iOS 6. You can check the client's [[UIDevice currentDevice]systemVersion] while using ALAssetsLibrary.

Resources