Hey! These docs are for version 7.0, which is no longer officially supported. Click here for the latest version, 9.0!

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>

Setup The 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.

1147

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.

For more details on setup see Designing your In-App Message.

1922

Add the Buttons

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).

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.

561

Optional: Add the In-App Trigger

You can trigger this message any time you like. For example, if you want to trigger this after being in the app for 30 seconds, set the trigger like so:

1067

👍

Done!

Just schedule and click Make Message Live to start location prompting.

Optional Setup With Triggers

Under the Triggers section select In-App Trigger and set location_prompt is true we will add this "key": "value" trigger programmatically in the app with addTrigger method soon.

1063

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");