位置检测唤醒应用程序

时间:2014-08-23 22:17:26

标签: objective-c ibeacon ios7.1

我有一个使用iBeacons的iOS应用程序。 我使用区域监视器等来设置信标等。

当我的应用程序被终止并且我进入该区域时,iOS不会唤醒我已终止的应用程序。

请告知。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSLog(@"applicationDidFinishLaunching");

    _locationManager = [[CLLocationManager alloc] init];
    _locationManager.delegate = self;
    _locationManager.desiredAccuracy=kCLLocationAccuracyBest;
    _locationManager.distanceFilter=1;
    _locationManager.pausesLocationUpdatesAutomatically = NO;
    CLBeaconRegion *region;

    region = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:@"F7826DA6-4FA2-4E98-8024-BC5B71E0893E"] major: 1 minor: 1 identifier: @"Test"];
    [region setNotifyEntryStateOnDisplay:YES];
    [region setNotifyOnExit:YES];
    [region setNotifyOnEntry:YES];

    [_locationManager startMonitoringForRegion:region];
    [_locationManager startRangingBeaconsInRegion:region];

    [_locationManager startUpdatingLocation];

    return YES;
}



- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
    NSLog(@"locationManager didDetermineState INSIDE for %@", region.identifier);

    UILocalNotification *notification = [[UILocalNotification alloc] init];
    notification.soundName = UILocalNotificationDefaultSoundName;
    notification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber]+1;

    notification.alertBody = @"Awake";

    [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}

- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
    NSLog(@"locationManager didRangeBeacons %d", beacons.count);
    CLBeacon *nearestExhibit = beacons && beacons.count > 0 ? [beacons firstObject] : nil;

    if (nearestExhibit &&
        (nearestExhibit.proximity == CLProximityImmediate ||
         nearestExhibit.proximity == CLProximityNear)
        && nearestExhibit.accuracy != -1
        && nearestExhibit.accuracy <= 10.0) {
        UILocalNotification *notification = [[UILocalNotification alloc] init];
        notification.soundName = UILocalNotificationDefaultSoundName;
        notification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber]+1;

        notification.alertBody = @"didRangeBeacons";

        [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
   }

}

1 个答案:

答案 0 :(得分:2)

如果通过&#34;终止&#34;你的意思是你已经使用任务切换器杀死了你的应用程序,然后在iOS 7.0.x上预期你描述的行为。从iOS 7.1开始,行为已经改变,因此您的应用程序会得到通知,就像它从未被终止一样。

我已经在7.1上验证了这个功能。如果您在7.1+上看到不同的内容,请仔细检查它是否能够正常运行而不会终止您的应用。

如果上述方法无效,请发布您的代码,以确保其设置正确。

更新:看到您的代码后,似乎所有内容都已正确设置。确保在安装了aspp的设备上安装了iOS 7.1+,然后:

  1. 关掉灯塔。
  2. 终止您的应用。
  3. 打开标识为F7826DA6-4FA2-4E98-8024-BC5B71E0893E 1 1的信标
  4. 等待up to 15 minutes通知。
相关问题