I am developing a Flutter app, and my initial screen is a custom splash screen. I’m trying to get the user’s location on this screen. If the app gets the user’s location, it will open the home screen widget with the location data as an argument. This argument is nullable, so if I can’t get the location, the home screen will still work fine.
Here is my code to get the location:
if (permissionGranted) {
try {
final location = await Geolocator.getCurrentPosition();
try {
// do some API call
} catch (e) {
print(e);
}
if (!mounted) return;
router. go(
'/',
extra: LatLng(location.latitude, location.longitude),
);
} catch (e) {
print('Error obtaining location: $e');
router.go(
'/',
);
}
} else {
router.go(
'/',
);
}
I am using go_router for routing and calling this from my splash screen’s init method, which is an async function.
The code works fine on Android and also on a real iPhone SE device. However, when I try to run my app on an iPad Air (simulator) or iPhone 13 mini (simulator) with iOS 17.5.1, it gets stuck on the splash screen forever.
Due to this issue, my app has been rejected twice from the App Store.
Questions:
- Are there any known issues with the Geolocator package on iOS simulators for iOS 17.5.1?
- Could this be an issue with my implementation of the go_router?
- Are there any additional configurations required specifically for iOS simulators that I might be missing?
Any help to debug and solve this issue would be greatly appreciated.
2
Answers
I have solved the issue and successfully published it.
I believe the problem was that some models of the iPad do not have GPS service. In that case, if you call
Geolocator.getCurrentPosition()
, it will return a null value.I encountered that by creating a custom function. The concept is that it will first call
Geolocator.getCurrentPosition()
and wait for some time. If it can't get any data, it will then callGeolocator.getLastKnownPosition()
and return the value. With this approach, the possibility of getting a null position is low.Here is my solution:
I am experiencing the same issue.
I resolved the problem of being stuck on the splash screen by adding the
NSLocationWhenInUseUsageDescription
andNSLocationAlwaysUsageDescription
to the info.plist.However, I am still encountering errors with the features that use location information, making it impossible to pass the review.
🙁
I resolved the errors by adding a timeout as follows.
to
Although this does not allow the use of location-related features, it will at least prevent the review from being rejected.