Using OneSignal's In-App Messages you can easily create and customize a "soft-prompt" to ask users to grant location tracking.
// Make sure you add one of the following permissions <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
//These are examples of how you may setup the app. See Apple's Guide on this: https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services // Example plist image: https://i.imgur.com/OZDQpyQ.png <key>NSLocationUsageDescription</key> <string>Your message goes here</string> <key>NSLocationWhenInUseUsageDescription</key> <string>Your message goes here</string> <key>NSLocationAlwaysAndWhenInUseUsageDescription</key> <string>Your message goes here</string> <key>NSLocationAlwaysUsageDescription</key> <string>Your message goes here</string> <key>UIBackgroundModes</key> <array> <string>location</string> <string>remote-notification</string> </array>
Head to Messages > In-App > New In-App
If location tracking is required for all users of the app, you can select "Show to all users", otherwise you can show to a particular Segment or your choice. We will show how/when to trigger this prompt below.
When prompting for location tracking, it is best to inform your user's why this is recommended. People don't usually share their location without a good reason. Explain with concise detail on what specific functionality this provides and why they should allow location tracking.
Create a button for the user to click if they wish to allow location tracking. In the button settings, select Add Click Action and Location Permission Prompt. When the user clicks this button, OneSignal will automatically trigger the native Location Permission Prompt (required for location tracking).
If location is already being tracked, adding this Click Action will prevent the entire IAM from showing.
The native Location Permission Prompt is required by Android and iOS for location tracking. Showing the native prompt and being denied limits the amount of times you can show it. By adding this pre-prompt it allows you to prompt the user as many times as required for opt-in.
You can trigger this message any time you like. However, if the device has already allowed location tracking permissions, the entire IAM will not show to the user until location tracking has been disabled.
For example, if you want to trigger this after being in the app for 30 seconds, set the trigger like so:
Under the Triggers section select In-App Trigger and set
true for example.
You will add this "key": "value" trigger programmatically in the app with
addTrigger method soon.
You can trigger this prompt anytime by simply use the
Make sure the trigger "key" and "value" match what you added to the IAM Trigger. In this example, we used
location_prompt for the key and
true for the value.
OneSignal.addTrigger("location_prompt", withValue: "true")
[OneSignal addTrigger:@"location_prompt" withVaue:@"true"]
Next see our guide on Location-Triggered Notifications.
Updated 4 months ago