我使用iBeacon顯示模板例如,在我使用本地notifications.when應用不支持後臺「didExitRegion」,「didEnterRegion」和「didRangeBeacons」方法獲取調用隨機。我不清楚這些方法在後臺和後臺處理時如何工作,任何人都可以在此協助我。提前感謝。關於應用程序在後臺或從後臺死亡時ibeacons的行爲?
這是示例代碼我使用:
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
[manager stopRangingBeaconsInRegion:(CLBeaconRegion*)region];
[self.locationManager stopUpdatingLocation];
NSLog(@"You exited the region.");
[self sendLocalNotificationWithMessage:@"You exited the region."];
}
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
[manager startRangingBeaconsInRegion:(CLBeaconRegion*)region];
[self.locationManager startUpdatingLocation];
NSLog(@"You entered the region.");
[self sendLocalNotificationWithMessage:@"You entered the region."];
}
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
NSString *message = @"i am in 3 meters.";
IMViewController *viewController = (IMViewController*)self.window.rootViewController;
viewController.beacons = beacons;
[viewController.tableView reloadData];
if(beacons.count > 0) {
CLBeacon *nearestBeacon = beacons.firstObject;
if(nearestBeacon.proximity == self.lastProximity ||
nearestBeacon.proximity == CLProximityUnknown)
{
return;
}
self.lastProximity = nearestBeacon.proximity;
NSLog(@"lastProximity: %ld", (long)self.lastProximity);
NSInteger str=(int)nearestBeacon.accuracy;
//NSString *distance=[NSString stringWithFormat:@"Distance: %d",(int)nearestBeacon.accuracy];
if (str ==3)
{
[self sendLocalNotificationWithMessage:message];
}
}
}
監測:進入/退出區域範圍時觸發的動作;在前臺,背景以及應用程序被殺害時都能工作。 測距:基於接近信標觸發的動作;只在前臺工作。試試這個教程http://www.raywenderlich.com/66584/ios7-ibeacons-tutorial –