OneSignal Help & Documentation

Welcome to the OneSignal New IA developer hub. You'll find comprehensive guides and documentation to help you start working with OneSignal New IA as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Discussions

Location Opt-In Prompt

Prompt Android and iOS mobile app users to allow location tracking.

Using OneSignal's In-App Messages you can easily create and customize a "soft-prompt" to ask users to grant location tracking.

Requirements:

See Android Location Tracking and iOS Location Tracking guidelines for frameworks to add to your app.
Location tracking permissions must be set in your AndroidManifest.xml and/or info.plist.

// 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"/>
//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>

New In-App Message

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.

Setup your message

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.

Add the Click Action

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.

Trigger the In-App Message

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.

Trigger After Time In-App

For example, if you want to trigger this after being in the app for 30 seconds, set the trigger like so:

Programmatic Triggers

Under the Triggers section select In-App Trigger and set location_prompt is true for example.

You will add this "key": "value" trigger programmatically in the app with addTrigger method soon.

Trigger The Prompt

You can trigger this prompt anytime by simply use the addTrigger method.

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", "true");
OneSignal.addTrigger("location_prompt", withValue: "true")
[OneSignal addTrigger:@"location_prompt" withVaue:@"true"]
OneSignal.AddTrigger("location_prompt", "true");
OneSignal.addTrigger("location_prompt", "true");
OneSignal.addTrigger("location_prompt", "true");
OneSignal.addTrigger("location_prompt", "true");

Updated 8 days ago



Location Opt-In Prompt


Prompt Android and iOS mobile app users to allow location tracking.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.