2016-05-20 9 views
0

Ich habe Probleme mit meiner App. Ich benutze Beacons, aber sie scheinen nicht in die Region einzutreten, wenn meine im Hintergrund läuft. Die Beacons sind austretend, treten aber nicht ein. Sie geben ein, wenn die App im Vordergrund ausgeführt wird. Unten ist mein Code. Danke im Voraus.ios beacons monitring hintergrund

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    NSUUID *beaconUUID = [[NSUUID alloc] initWithUUIDString:@"BEC26202-A8D8-4A94-80FC-9AC1DE37DAA6"]; 
    NSString *regionIdentifier = @"us.iBeaconModules"; 
    self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:beaconUUID identifier:regionIdentifier]; 
    NSLog(@"%@",beaconUUID); 

     [self.locationManager requestAlwaysAuthorization]; 


    self.locationManager.delegate = self; 
    self.locationManager.pausesLocationUpdatesAutomatically = NO; 
    self.locationManager.allowsBackgroundLocationUpdates=YES; 
    [self.locationManager startRangingBeaconsInRegion:self.beaconRegion]; 
    [self.locationManager startUpdatingLocation]; 
     self.beaconRegion.notifyOnEntry=YES; 
     self.beaconRegion.notifyOnExit=YES; 
     self.beaconRegion.notifyEntryStateOnDisplay=YES; 
    [self.locationManager startMonitoringForRegion:self.beaconRegion]; 



    return YES; 
} 

-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { 
    [manager startRangingBeaconsInRegion:(CLBeaconRegion*)region]; 
    [self.locationManager startUpdatingLocation]; 
    CLBeaconRegion *test = (CLBeaconRegion*)region; 
    NSLog(@"You entered the region. %@", test.minor); 
    [self sendLocalNotificationWithMessage:@"You enterd the region."]; 
    UILocalNotification *notification = [[UILocalNotification alloc] init]; 
    notification.alertBody = @"Are you forgetting something?"; 
    notification.soundName = @"Default"; 
    [[UIApplication sharedApplication] presentLocalNotificationNow:notification]; 
} 

-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { 

    CLBeaconRegion *test = (CLBeaconRegion*)region; 

    NSLog(@"You exited the region.%@", test.minor); 
    [self sendLocalNotificationWithMessage:@"You exited the region. "]; 

} 

-(void)sendLocalNotificationWithMessage:(NSString*)message { 
    UILocalNotification *notification = [[UILocalNotification alloc] init]; 
    notification.alertBody = message; 
    [[UIApplication sharedApplication] scheduleLocalNotification:notification]; 
} 

- (void) locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region 
{ 
    [self.locationManager requestStateForRegion:self.beaconRegion]; 
} 

-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region 
{ 
    if (state == CLRegionStateInside) 
    { 
     //Start Ranging 
     [manager startRangingBeaconsInRegion:self.beaconRegion]; 
    } 
    else 
    { 
     //Stop Ranging here 
    } 
} 

Antwort

0

Bitte fügen Sie in Ihre plist folgenden NSLocationAlwaysUsageDescription

NSLocationAlwaysUsageDescription Diese Anwendung erfordert Standortdienste

+0

ich das gleiche Ergebnis zu arbeiten. –

+0

fügen Sie das einfach in didFinishLaunchingWithOptions hinzu locationManager = [[CLLocationManager alloc] init]; [locationManager requestWhenInUseAuthorization]; [locationManager requestAlwaysAuthorization]; [self.locationManagerForIbeacan setRegions: @ [Region]]; [self.locationManagerForIbeacan startMonitoringBeacons]; – user3306145

+0

funktioniert immer noch nicht –

Verwandte Themen