DeviceReady ios calles when double click home button


#1

Hey everyone,

I am making an app in ionic and i’ve got a weird problem. I have a device ready event but it doens’t fire until i double press the homebutton twice --> going into multitasking (ios). Has anyone ever experienced the same problem ?

The project is still in early stages, but the intention is that you can walk around and scan ibeacons. Then you get the acording information over the place you are.

code :

.controller('BluetoothController',function($scope,$ionicPlatform){
var id_HTML = document.getElementById('id');
var proximity_HTML = document.getElementById('proximity');
var range_HTML = document.getElementById('range');

$ionicPlatform.ready(function() {
	$scope.deviceReady = true;
	console.log("deviceready");	
})

$scope.beaconRegion = {
		id: 'Iphone',
		uuid: '7C146FE2-9B42-40A8-B4BF-9ABF5B33472F',
		major: 1,
		minor: 1000	
};

$scope.range = "starting proximity";
$scope.beaconRegion;

$scope.StartScanBTdevices = function(){
	//when the start scanning button gets clicked, this get activated
	$scope.isScanning = true;
			
	startScanForBeacons();
}

$scope.StopScanBTdevices = function(){
	$scope.isScanning = false;
	

	cordova.plugins.locationManager.stopRangingBeaconsInRegion($scope.beaconRegion)
    .fail(console.error)
    .done();
	
}

function startScanForBeacons(){

		// required in iOS 8+
		//cordova.plugins.locationManager.requestWhenInUseAuthorization(); 
		cordova.plugins.locationManager.requestAlwaysAuthorization()

		$scope.delegate = new cordova.plugins.locationManager.Delegate().implement({

	    didDetermineStateForRegion: function (pluginResult) {
	    	//alert("didDetermineStateForRegion");
	        cordova.plugins.locationManager.appendToDeviceLog('[DOM] didDetermineStateForRegion: '
	            + JSON.stringify(pluginResult));
	    },

	    didStartMonitoringForRegion: function (pluginResult) {
	    	$scope.range = JSON.stringify(pluginResult);
	    },

	    didRangeBeaconsInRegion: function (pluginResult) {
	    
	    	if(pluginResult.beacons[0].accuracy > 0)
	    	{
	    		beaconFound(pluginResult.region.identifier,
	    					pluginResult.beacons[0].accuracy,
	    					pluginResult.beacons[0].proximity );
	    	}
	    	else{
	    		
				id_HTML.innerHTML = "No Ibeacon found ";
				proximity_HTML.innerHTML = "...";
				range_HTML.innerHTML="";

				return;
	    	}

	    }
	});

	
	$scope.beaconRegion = new cordova.plugins.locationManager.BeaconRegion($scope.beaconRegion.id, $scope.beaconRegion.uuid, $scope.beaconRegion.major, $scope.beaconRegion.minor);
	cordova.plugins.locationManager.setDelegate($scope.delegate);

	// required in iOS 8+
	cordova.plugins.locationManager.requestWhenInUseAuthorization(); 
	// or cordova.plugins.locationManager.requestAlwaysAuthorization()

	
	cordova.plugins.locationManager.startRangingBeaconsInRegion($scope.beaconRegion)
    .fail(console.error)
    .done();		
}

function beaconFound(beacon_id, range, proximity){
	id_HTML.innerHTML = "ID: " + beacon_id; 
	range_HTML.innerHTML ="Range: " + range + "m";
	

	switch (proximity){
	case "ProximityImmediate" : 
		proximity_HTML.innerHTML = "Immediate";
		break;
	case "ProximityNear" :
		proximity_HTML.innerHTML = "Near";
		break; 
	case "ProximityFar" :
		proximity_HTML.innerHTML = "Far";
		break;
	default:
		proximity_HTML.innerHTML = "proximity";
		break; 
	}
	return;
	

}	

})