React Native SDK Examples & Troubleshooting
Complete implementation examples and solutions to common integration challenges.
Complete Implementation Example
DoorstepAI SDK Test App
This is a complete example of a test app that demonstrates all SDK functionality:
App.js
import { DoorstepAI, RootDoorstepAI } from '@doorstepai/dropoff-sdk';
import { useEffect } from 'react';
import { View, StyleSheet, Button } from 'react-native';
export default function App() {
useEffect(() => {
DoorstepAI.enableDevMode();
});
return (
<View style={styles.container}>
<RootDoorstepAI
apiKey="some_api_key"
notificationTitle="Tracking..."
notificationText="Tracking your delivery"
/>
<Button
title="Start Delivery"
onPress={() => {
DoorstepAI.startDeliveryByPlaceID('destination_place_id', 'id_1');
}}
/>
<View style={styles.spacer} />
<Button
title="Stop Delivery"
onPress={() => {
DoorstepAI.stopDelivery('id_1');
}}
/>
<View style={styles.spacer} />
<Button
title="New Event"
onPress={() => {
DoorstepAI.newEvent('event_name', 'id_1');
}}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
spacer: {
height: 20,
},
});
Troubleshooting
Common Issues and Solutions
1. SDK Initialization Errors
Problem: SDK fails to initialize or API key errors occur.
Solutions:
// Check API key validity
const validateAPIKey = () => {
const apiKey = 'your_api_key_here';
if (!apiKey || apiKey === 'your_api_key_here') {
console.error('❌ Invalid API key');
Alert.alert('Error', 'Please configure a valid API key');
return false;
}
console.log('✅ API key configured');
return true;
};
// Initialize with error handling
const initializeSDK = async () => {
try {
if (Platform.OS === 'android') {
await DoorstepAI.init(
'Delivery Intelligence',
'Creating precision dropoff intelligence'
);
}
DoorstepAI.setApiKey('your_api_key_here');
console.log('✅ SDK initialized successfully');
} catch (error) {
console.error('❌ SDK initialization failed:', error);
Alert.alert('Error', `Failed to initialize SDK: ${error.message}`);
}
};
2. Permission Issues
Problem: Location or activity recognition permissions are denied.
Solutions:
import { PermissionsAndroid, Platform, Alert } from 'react-native';
const checkAndRequestPermissions = async () => {
if (Platform.OS === 'android') {
try {
const permissionsToRequest = [
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
PermissionsAndroid.PERMISSIONS.ACTIVITY_RECOGNITION,
];
// Add background location permission for Android 10+ (API 29+)
if (Platform.Version >= 29) {
permissionsToRequest.push(PermissionsAndroid.PERMISSIONS.ACCESS_BACKGROUND_LOCATION);
}
const granted = await PermissionsAndroid.requestMultiple(permissionsToRequest);
const allGranted = Object.values(granted).every(
permission => permission === PermissionsAndroid.RESULTS.GRANTED
);
if (allGranted) {
console.log('✅ All permissions granted');
} else {
console.warn('❌ Some permissions denied');
Alert.alert(
'Permissions Required',
'This app needs location and activity recognition permissions to provide delivery tracking. Please grant these permissions in Settings.',
[
{ text: 'Cancel', style: 'cancel' },
{ text: 'Open Settings', onPress: () => Linking.openSettings() }
]
);
}
} catch (err) {
console.warn('❌ Error requesting permissions:', err);
}
} else if (Platform.OS === 'ios') {
console.log('📱 iOS: Ensure location and motion usage descriptions are in Info.plist');
}
};
Testing Checklist
Before releasing your React Native integration:
- ✅ SDK initializes successfully on both iOS and Android
- ✅ API key is valid and securely stored
- ✅ All required permissions are declared in native manifests
- ✅ Runtime permissions are properly requested and handled
- ✅ Notification permission is granted (Android 13+)
- ✅ Error handling is implemented for all SDK methods
- ✅ Delivery IDs are unique and meaningful
- ✅ App state changes are handled correctly
- ✅ Background tracking works on both platforms
- ✅ Location updates are received in background mode