I am new to iOS. Is it possible to show a custom view or dialog in place of the default iOS location permission dialog?
No, this dialog is presented by the operating system and you cannot modify it. It is an important part of privacy management that the dialog is presented in a consistent way for all apps and that apps cannot modify the permission process.
You can display a custom view or alert prior to requesting permissions that explains what is happening and the need to click "allow" on the alert that is about to be presented
Direct Answer is it's not possible
explanation :
Only option is set description string by using Cocoa Keys(The keys associated with the Cocoa touch environments)
Add one of these key to
NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
Info.plist and set it's value to whatever which describe the purpose of getting location
ex:
MyApp picks you up from where you are. To book airport rides, choose “Allow” so the app can find your location.
Important: To protect user privacy, an iOS app linked on or after iOS 10.0, and which accesses the user’s location information, must statically declare the intent to do so. Include the NSLocationAlwaysUsageDescription key in your app’s Info.plist file and provide a purpose string for this key. If your app attempts to access the user’s location information without a corresponding purpose string, your app exits.
If you looking for localization for that message
Link
Related
I have an iOS app that uses the Google maps library which I have added via CocoaPods. This app fetches user location even in background so it asks the user for NSLocationAlwaysUsageDescription.
But upon running the app from Xcode, I get the correct permission alert but I also get the following error message in the console.
This app has attempted to access privacy-sensitive data without a
usage description. The app's Info.plist must contain an
NSLocationWhenInUseUsageDescription key with a string value explaining
to the user how the app uses this data
Doesn't NSLocationAlwaysUsageDescription automatically allow when in usage as well? Because I don't want the When In Use option to be available in the Settings because if the user later changes to that, it will cause the app to behave not as intended.
You have to add a key value pair of NSLocationAlwaysUsageDescription as key and value is like you have to notify user , or something else that user can understand that this app is going to use gps location.
You can try this or add this in your plist
Privacy - Location Always Usage Description as key and
Application would like to use your location. By allowing background locations, we can notify you when a customer is requesting for service. Continued use of GPS running in the background can dramatically decrease battery life as value
I'm trying to access the last photo from the user's camera roll within an iOS keyboard extension. I have allowed full access to the keyboard and allowed access to the Photo Library. But every time I try to run PHImageManager.default().requestImage... the keyboard is terminated...
Is it not possible to use PHImageManager in a keyboard extension?
According to App Extension Programming Guide it should be possible.
If you request open access by setting this key’s value to YES, your keyboard gains the following capabilities, each with a concomitant responsibility in terms of user trust:
Access to Location Services, the Address Book database, and the Camera Roll, each requiring user permission on first access
only allowing full access in the info.plist file is not enough, also the user has to allow full access in the keyboards settings.
On your device go to Settings -> General -> Keyboard -> Keyboards -> %NAME_OF_YOUR_KEYBOARD% and turn on Allow Full Access!
But I'm still facing problems here: although i have added a NSPhotoLibraryUsageDescription to my extensions info.plist
my keyboard terminates with following message:
[access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.
As in many apps, also in my app I have a "Settings" view.
I would like to add an item composed by text + UISwitch in order to give user possibility to change the "location services" permissions: when switch is enabled "allow location services: always", when is disabled "allow location services: never".
Question is: could this a reason for an Apple App Rejection?
I read all guidelines but I can't find an answer to my question.
Links
Review rejections.
Review guidelines.
UI Tips.
Regardless of app store review, what you're thinking of doing isn't technically possible. Your app can only request location permissions, it can't then tell the system that it doesn't need them any more.
For the user to amend location permissions they have to open the iOS settings app and go to the page for your app. You can provide a link from within your app to do this, using the UIApplicationOpenSettingsURLString constant to build and open a URL.
I don't know your code so I'll try to help you writing a few lines to follow to understand Apple reject.
So the first thing you need to do is to add one or both of the following keys to your Info.plist file:
NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription
Next you need to request authorization for the corresponding location method, WhenInUse or Background. Use one of these calls:
requestWhenInUseAuthorization
requestAlwaysAuthorization
Location types that you need Always authorization to use:
Significant Location Change
Boundary Crossing (Geofences)
Background Location Updates (e.g. Fitness, Navigation apps) iBeacons
Visited Locations (iOS 8+)
Deferred Location Updates
The iOS Human Interface Guidelines state:
You can provide text that appears in the alert, below a
system-provided title such as ““App Name” Would Like to Access Your
Contacts”
Where? There's no option for me to add my own message in EKEventStore's requestAccessToEntityType:completion: method. I want to add a completely new calendar to the user's calendar store, not modify an existing one, if that matters.
Am I looking in the right place?
You can add NSCalendarsUsageDescription key to your info.Plist and that should be enough
Source : Information Property List Key Reference
NSCalendarsUsageDescription (String - iOS) describes the reason that
the app accesses the user’s calendars. When the system prompts the
user to allow access, this string is displayed as part of the dialog box.
This key is supported in iOS 6.0 and later.
Is it possible to customize the default alert message when the iPhone wants to use users current location. I want to change not only the text but also the default blue screen alert view. Is it possible ?
Thanks.
Not possible. From documentation,
Important: In addition to hardware not being available, the user has
the option of denying an application’s access to location service
data. During its initial uses by an application, the Core Location
framework prompts the user to confirm that using the location service
is acceptable. If the user denies the request, the CLLocationManager
object reports an appropriate error to its delegate during future
requests. You can also check the application’s explicit authorization
status using the authorizationStatus method.
The alert is prompted by Core location framework. We don't have any control over it.
EDIT : To add up, from this Apple developer forum thread (login required)
That alert is shown in a standard fashion for all applications for
privacy reasons. The user's current location is sensitive
information, and we want to be sure that they give their informed
consent to any use of it on the device. The way that we do that is by
providing a clear, consistent mechanism for the user to give their
consent. If applications were allowed to override or disable the
alert, then that consistency would be lost.
and the answerer is an Apple employee..
Years later, Apple did implement some customization options!
Have a look at the documentation
documentation
If you put one of the following key in your info.plist (depending on your usage of the location services), you can specify a custom string, that is displayed in the default alert additionally.
NSLocationUsageDescription (available since iOS6)
NSLocationWhenInUseUsageDescription (since iOS8)
NSLocationAlwaysUsageDescription (since iOS8)