final ImagePicker _picker = ImagePicker();
XFile? _imageFile;
dynamic _pickImageError;
void _pickImageFromGallery() async {
try {
final imagePicker = await _picker.pickImage(
source: ImageSource.gallery,
maxWidth: 300,
imageQuality: 80,
maxHeight: 300,
);
setState(() {
_imageFile = imagePicker;
});
} catch (e) {
_pickImageError = e;
print(_pickImageError);
}
}
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSCameraUsageDescription</key>
<string>pick image from camera</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>Add photo liabrary description</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>pick image from gallery</string>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
i'm using in pubspec.yaml
environment:
sdk: '>=2.18.1 <3.0.0'
dependencies:
flutter:
sdk: flutter
image_picker: ^0.8.6
firebase_auth: ^4.2.1
cloud_firestore: ^4.2.0
firebase_storage: ^11.0.8
firebase_core: ^2.4.0
As described in the image_picker README, you can only select non-HEIC images, when using the iOS Simulator. Accordingly, the easiest way to select a photo is via a physical iOS device.
Related
video_player does not play network Video on IOS Simulator.
NSAppTransportSecurity was added to info.plist.
https://pub.dev/packages/video_player
I did add here .
void initState() {
super.initState();
_controller = VideoPlayerController.network(
widget.videoLink,
videoPlayerOptions: VideoPlayerOptions(),
)..initialize().then((_) {
setState(() {});
});
_controller.play();
_controller.setLooping(true);
setState(() {});
}
<false/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
You must have a SSL certificate in which the video is uploaded
Since 12th october 2022, reader's app with external account management/purchase must have to declare a new entitlement.
External Link Account
Enable qualifying apps to link to an external website for account creation or management.
https://developer.apple.com/documentation/storekit/external_link_account
I can't build because :
Swift Compiler Error (Xcode): Cannot find 'ExternalLinkAccount' in scope
Configure the SKExternalLinkAccount property list key.
<plist>
<dict>
<key>SKExternalLinkAccount</key>
<dict>
<key>*</key>
<string>https://example.com</string>
<key>jp</key>
<string>https://example.com/jp</string>
</dict>
</dict>
</plist>
Runner plist
<key>com.apple.developer.storekit.external-link.account</key>
<true/>
Runner entitlement
<plist>
<dict>
<key>com.apple.developer.storekit.external-link.account</key>
<true/>
</dict>
</plist>
ios build (with flutter run) :
Swift Compiler Error (Xcode): Cannot find 'ExternalLinkAccount' in scope
My code in a custom swift file (called with a platform specific call)
import SwiftUI
struct ExternalLinkAccountModal: View {
var body: some View {
Text("Hello, world!")
.padding()
.onAppear {
Task {
await executeTask()
}
}
}
}
struct ExternalLinkAccountModal_Previews: PreviewProvider {
static var previews: some View {
ExternalLinkAccountModal(onConfirm: nil, onCancel: nil)
.previewDevice("iPhone 13")
.previewInterfaceOrientation(.portrait)
}
}
func executeTask() async {
let basicTask = Task {
if await ExternalLinkAccount.canOpen {
do {
try await ExternalLinkAccount.open()
} catch {
print("ExternalLinkAccount.open() error \(error)")
}
}
}
}
Provisioning profile
My provisioning profile is well configured and accepted by Apple Developper :
Associated Domains, External Link Account, In-App Purchase, Push Notifications
Can you help to fix this ?
I'm using osx Ventura and ios16 platform for developping.
I'm using qr_code_scanner to scan barcodes in my Flutter app and it works fine for Android, but when I try to scan for iOS a pop-up appears and looks like:
I'm using the descriptions Flutter code that looks like the following:
QRView(
key: qrKey,
onQRViewCreated: (controller) => {
controller.scannedDataStream.listen((code) async {
...
})
})
And in my Info.plist file I have the following fields:
<key>io.flutter.embedded_views_preview</key>
<true/>
<key>NSCameraUsageDescription</key>
<string>Camera permission is required to scan QR codes.</string>
However even with these settings set, I can't seem to figure out how to have access to the camera. Thanks for any help.
Update
I followed #EvgeniyTrubilo suggestion and used permission_handler to request permission using the following code:
void getCameraPermission() async {
print(await Permission.camera.status); // prints PermissionStatus.granted
var status = await Permission.camera.status;
if (!status.isGranted) {
final result = await Permission.camera.request();
if (result.isGranted) {
setState(() {
canShowQRScanner = true;
});
} else {
Scaffold.of(context).showSnackBar(
SnackBar(content: Text('Please enable camera to scan barcodes')));
Navigator.of(context).pop();
}
} else {
setState(() {
canShowQRScanner = true;
});
}
}
The first time this code was executed it successfully requested permission to access camera, and once permission was granted, the same error showed up. Sequential tries the print statement at the top of the above function said the Permission was granted??
Update 2x
Just realized you can mock the camera in an iOS simulator like you can on Android. I will try this on an actual device and update.
You can use permission_handler. With this, you could ask for camera permission before build QRView. Of course, you should build QRView after camera permission is enabled.
I'm not sure it would be right solution for your issue, but I think that would be an awesome improvement.
I am using the below code to get pick image in flutter application, when the code is run on Android it works fine, but when the same code is run on iOS it crashes the app while tapping the button to pick the image.
How should I resolve it?
ERROR I GET
Lost connection to device.
final ImagePicker _picker = ImagePicker();
Future getImage() async {
print("get image");
PickedFile image = await _picker.getImage(source: ImageSource.gallery);
if (image != null) {
setState(() {
final File file = File(image.path);
avatarImageFile = file;
isLoading = true;
});
}
}
info.plist properties
You have to add the below permission in Info.plist file in XCode.
Camera :
Key : Privacy - Camera Usage Description
Value : $(PRODUCT_NAME) camera use
Photo :
Key : Privacy - Photo Library Usage Description
Value : $(PRODUCT_NAME) photo use
since my iPhone Simulator has no camera, it is impossible to debug this on my simulator. But I have a physical device, however, with those stupid provisioning profiles, I am only able to send release versions to my actual iPhone 7, which means it doesnt return debug info.
However, with the help of TRY CATCH I was able to pinpoint when the actual iPhone crashes: it is this line of code:
file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
Directory = "Sample",
Name = "test.jpg"
});
The whole code looks like this:
await CrossMedia.Current.Initialize();
Plugin.Media.Abstractions.MediaFile file = null;
try
{
file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
Directory = "Sample",
Name = "test.jpg"
});
}
catch
{
await DisplayAlert("1", ":( No camera available.", "OK");
}
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
await DisplayAlert("No Camera", ":( No camera available.", "OK");
return;
}
if (file == null)
return;
Since it runs into the catch block here, I know it is the abolev line that throws the error.
This is the james montamagno plugin.
Can you guys help me out here? Might this be a permission problem?
Thank you!
Adding this to info.plist:
<key>NSCameraUsageDescription</key>
<string>This app needs access to the camera to take photos.</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to photos.</string>
Solved the issue!