CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-react-native-onesignal

React Native SDK for OneSignal's push notification, email, SMS, and in-app messaging service

Pending
Overview
Eval results
Files

location.mddocs/

Location Services

Location permission and sharing management for geo-targeted messaging capabilities.

Capabilities

Location Permission

Request and manage location permissions for geo-targeting features.

/**
 * Prompts the user for location permissions to allow geotagging from the OneSignal dashboard.
 */
function requestPermission(): void;

Usage Example:

import { OneSignal } from "react-native-onesignal";

// Request location permission for geo-targeting
OneSignal.Location.requestPermission();

Location Sharing Control

Control whether location data is shared with OneSignal for geo-targeting.

/**
 * Disable or enable location collection (defaults to enabled if your app has location permission).
 * @param shared - Whether to share location data with OneSignal
 */
function setShared(shared: boolean): void;

/**
 * Checks if location collection is enabled or disabled.
 * @returns Promise resolving to whether location sharing is enabled
 */
function isShared(): Promise<boolean>;

Usage Examples:

// Enable location sharing for geo-targeted messages
OneSignal.Location.setShared(true);

// Disable location sharing (privacy-focused users)
OneSignal.Location.setShared(false);

// Check current location sharing status
const isLocationShared = await OneSignal.Location.isShared();
console.log('Location sharing enabled:', isLocationShared);

Complete Location Setup Flow

import { OneSignal } from "react-native-onesignal";

async function setupLocationServices() {
  try {
    // Check if location is currently being shared
    const currentlyShared = await OneSignal.Location.isShared();
    console.log('Current location sharing status:', currentlyShared);
    
    if (!currentlyShared) {
      // Request location permission from user
      OneSignal.Location.requestPermission();
      
      // Enable location sharing after permission granted
      // Note: You may want to wait for permission callback before enabling
      OneSignal.Location.setShared(true);
      
      // Verify it was enabled
      const newStatus = await OneSignal.Location.isShared();
      console.log('Location sharing now enabled:', newStatus);
    }
  } catch (error) {
    console.error('Error setting up location services:', error);
  }
}

// Call during app initialization
setupLocationServices();

Privacy Considerations

User Control

// Provide user control over location sharing
function handleLocationPrivacyToggle(enableLocation: boolean) {
  if (enableLocation) {
    // User opted in to location sharing
    OneSignal.Location.requestPermission();
    OneSignal.Location.setShared(true);
  } else {
    // User opted out - disable location sharing
    OneSignal.Location.setShared(false);
  }
}

Conditional Location Features

async function enableLocationFeaturesIfAllowed() {
  const isShared = await OneSignal.Location.isShared();
  
  if (isShared) {
    // Enable location-based features in your app
    console.log('Location-based notifications enabled');
    
    // You can now use geo-targeted campaigns from OneSignal dashboard
  } else {
    // Provide alternative non-location-based experience
    console.log('Using non-location-based targeting');
  }
}

GDPR Compliance

// For GDPR compliance, check consent before enabling location
function handleGDPRLocationConsent(hasConsent: boolean) {
  if (hasConsent) {
    OneSignal.Location.requestPermission();
    OneSignal.Location.setShared(true);
  } else {
    // Ensure location sharing is disabled
    OneSignal.Location.setShared(false);
  }
}

Use Cases

Retail Apps

// Enable location for store-based promotions
async function setupRetailLocationFeatures() {
  const isShared = await OneSignal.Location.isShared();
  
  if (!isShared) {
    // Explain benefits to user
    showLocationBenefitsModal({
      onAccept: () => {
        OneSignal.Location.requestPermission();
        OneSignal.Location.setShared(true);
      },
      onDecline: () => {
        OneSignal.Location.setShared(false);
      }
    });
  }
}

Event Apps

// Location for event-based notifications
async function setupEventLocationTracking() {
  // Request location for event proximity notifications
  OneSignal.Location.requestPermission();
  OneSignal.Location.setShared(true);
  
  console.log('Event location tracking enabled');
  // Users will now receive notifications based on proximity to event venues
}

Delivery Apps

// Essential location tracking for delivery apps
async function setupDeliveryLocationTracking() {
  // Location is critical for delivery apps
  OneSignal.Location.requestPermission();
  OneSignal.Location.setShared(true);
  
  const isEnabled = await OneSignal.Location.isShared();
  if (!isEnabled) {
    // Show critical location requirement dialog
    showLocationRequiredDialog();
  }
}

Weather Apps

// Location for weather-based alerts
async function setupWeatherLocationServices() {
  OneSignal.Location.requestPermission();
  OneSignal.Location.setShared(true);
  
  // Users will receive weather alerts based on their location
  console.log('Weather location services enabled');
}

Platform Behavior

iOS

  • Requests standard iOS location permission dialog
  • Respects user's location privacy settings
  • Integrates with iOS location services

Android

  • Requests Android location permissions
  • Handles runtime permission requests
  • Respects Android location settings
import { Platform } from 'react-native';

function platformSpecificLocationSetup() {
  if (Platform.OS === 'ios') {
    // iOS-specific location setup if needed
    OneSignal.Location.requestPermission();
  } else if (Platform.OS === 'android') {
    // Android-specific location setup if needed  
    OneSignal.Location.requestPermission();
  }
  
  // Common location sharing setup
  OneSignal.Location.setShared(true);
}

Install with Tessl CLI

npx tessl i tessl/npm-react-native-onesignal

docs

core-sdk.md

in-app-messages.md

index.md

live-activities.md

location.md

notifications.md

push-subscription.md

session.md

user-management.md

tile.json