react-native-beacons-manager
react-native-beacons-manager copied to clipboard
Everything stopped in background mode IOS 13
Version
1.0.7
Platform
iOS
OS version
13
Steps to reproduce
I try to use lists.push
to check what's happened in background mode, but the list not push until I open foreground again.
This is my code.
import React, { Component } from 'react';
import { View, Text, TouchableOpacity, FlatList } from 'react-native';
import { connect } from 'react-redux';
import styles from './style';
import AsyncStorage from '@react-native-community/async-storage';
import { constants } from '../../config';
import { DeviceEventEmitter } from 'react-native'
import Beacons from 'react-native-beacons-manager'
class HomeScreen extends Component {
static navigationOptions = ({ navigation }) => {
return {
title: 'Home'
};
};
constructor(props) {
super(props);
this.state = {
lists: [
{
'id': '124',
'name': 'initName',
}
],
};
}
componentDidMount = async() => {
this.startScanIBeacon();
}
startScanIBeacon() {
var region = {
identifier: 'Estimotes',
uuid: '7BA50575-D92E-42AE-AFE1-142B57E04F05'
};
Beacons.requestAlwaysAuthorization();
Beacons.startMonitoringForRegion(region);
Beacons.startRangingBeaconsInRegion(region);
Beacons.startUpdatingLocation();
// Listen for beacon changes
var subscription = DeviceEventEmitter.addListener(
'beaconsDidRange',
(data) => {
console.log('beaconsDidRange', data);
const lists = this.state.lists;
lists.push({
'id': new Date().toISOString(),
'name': 'beaconsDidRange'
})
this.setState({ lists });
}
);
var subscription1 = DeviceEventEmitter.addListener(
'regionDidEnter',
(data) => {
console.log('startUpdatingLocation', data);
const lists = this.state.lists;
lists.push({
'id': new Date().toISOString(),
'name': 'beaconsDidRange'
})
this.setState({ lists });
}
);
var subscription2 = DeviceEventEmitter.addListener(
'regionDidExit',
(data) => {
console.log('regionDidExit', data);
const lists = this.state.lists;
lists.push({
'id': new Date().toISOString(),
'name': 'regionDidExit'
})
this.setState({ lists });
}
);
}
_goToScreen = (screen) => {
this.props.navigation.navigate(screen);
}
_setUsername = (username) => {
this.props.setUsername(username);
}
render() {
return (
<View style={styles.container}>
<Text style={styles.san_id}>{this.state.san_id}</Text>
<FlatList
data={ this.state.lists }
renderItem={ this.Item }
keyExtractor={ item => item.id }
/>
<TouchableOpacity onPress={() => this._goToScreen('AppSetting')}>
<Text style={styles.link}>カードID設定</Text>
</TouchableOpacity>
</View>
);
}
Item = ({ item }) => {
return (
<View>
<Text>{item.name}</Text>
</View>
);
}
}
const mapStateToProps = state => ({});
const mapDispatchToProps = dispatch => ({});
export default connect(mapStateToProps, mapDispatchToProps)(HomeScreen);
Expected behavior
In background, the list should be updated.
Actual behavior
Just update when I open app foreground again/
In case of iOS, you need to add a call to Beacons.allowsBackgroundLocationUpdates(true) in order to activate it (default is false). Do it after you request the permissions (Beacons.requestAlwaysAuthorization();
) just to be safe. With #193 the missing binding to have it callable from javascript side was added and its not available in the master branch. Please give it a try and close the issue if it works :)