web-dev-qa-db-ja.com

レンジングビーコンはアプリの実行時にのみ機能しますか?

アプリが実行されていないときに、これを機能させるのに苦労しています。私が持っています locationManager:didRangeBeacons:inRegion:が実装され、アプリがフォアグラウンドまたはバックグラウンドで実行されているときに呼び出されますが、アプリを終了して画面をロックしても何も実行されないようです。位置情報サービスのアイコンが消え、ビーコン範囲に入ったことを知らない。 LocalNotificationは引き続き機能しますか?

ロケーションの更新があり、バックグラウンドモード(XCode 5)で選択されたBluetooth LEアクセサリを使用しています。

どんな助けも大歓迎です。

-(void)watchForEvents { // this is called from application:didFinishLaunchingWithOptions
    id class = NSClassFromString(@"CLBeaconRegion");
    if (!class) {
        return;
    }

    CLBeaconRegion * rflBeacon = [[CLBeaconRegion alloc] initWithProximityUUID:kBeaconUUID identifier:kBeaconString];
    rflBeacon.notifyOnEntry = YES;
    rflBeacon.notifyOnExit = NO;
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    [self.locationManager startRangingBeaconsInRegion:rflBeacon];
    [self.locationManager startMonitoringForRegion:rflBeacon];
}

-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
    if (beacons.count == 0 || eventRanged) { // breakpoint set here for testing
        return;
    }

    eventRanged = YES;
    if (backgroundMode) { // this is set in the EnterBackground/Foreground delegate calls
        UILocalNotification *notification = [[UILocalNotification alloc] init];
        notification.alertBody = [NSString stringWithFormat:@"Welcome to the %@ event.",region.identifier];
        notification.soundName = UILocalNotificationDefaultSoundName;
        [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
    }

    // normal processing here...
}
23
Aaron Bratcher

監視により、実行されていないアプリを起動できます。レンジングはできません。

アプリを起動して監視するための鍵は、CLBeaconRegion:region.notifyEntryStateOnDisplay = YES; これにより、電話機を完全に再起動した後でも、リージョンの移行時にアプリを起動できます。ただし、いくつか注意点があります。

  1. アプリは数秒間だけバックグラウンドで起動します。 (NSLogステートメントをapplicationDidEnterBackgroundおよびAppDelegateの他のメソッドに追加して、何が起こっているのかを確認してください。)
  2. iOSは、CLBeaconRegionを入力したかどうかを判断するために独自の時間をかけることができます。私はそれが最大4分かかるのを見ました。

測距に関しては、測距でアプリを起動することはできませんが、アプリに監視と測距の両方を同時に実行させることができます。監視によってアプリが起動され、数秒間バックグラウンドに置かれると、レンジングコールバックがすぐに開始されます。これにより、アプリの実行中にクイックレンジングアクションを実行できます。

編集:さらなる調査により、notifyEntryStateOnDisplayがバックグラウンド監視に影響を与えないことが証明されたため、このフラグがあるかどうかに関係なく上記は機能するはずです。 発生する可能性のある遅延の詳細な説明と説明を参照してください

11
davidgyoung

バックグラウンドで範囲を設定するために従う必要があるプロセスは次のとおりです。

  1. CLBeaconRegionについては、常にバックグラウンドまたはフォアグラウンドで監視を維持し、notifyEntryStateOnDisplay = YESを維持します
  2. notifyEntryStateOnDisplayはバックグラウンドでlocationManager:didDetermineState:forRegion:を呼び出すので、このデリゲート呼び出しを実装してください...

...このような:

- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region{

   if (state == CLRegionStateInside) {


        //Start Ranging
        [manager startRangingBeaconsInRegion:region];
    }

   else{

        //Stop Ranging
        [manager stopRangingBeaconsInRegion:region];
    }

}

これがお役に立てば幸いです。

7
manishnath

Location Updatesを使用して、バックグラウンドでビーコンを範囲指定するiOS 9のコード:

  1. プロジェクト設定->機能->バックグラウンドモード-> _Location Updates_と_Uses Bluetooth LE accessories_をONに切り替えます。

  2. CLLocationManagerを作成し、Alwaysモニタリング許可を要求します(アプリの_Application does not run in background_のNOおよびNSLocationAlwaysUsageDescriptionに_info.plist_を追加することを忘れないでください)。次のプロパティを設定します。

    _locationManager!.delegate = self
    locationManager!.pausesLocationUpdatesAutomatically = false
    locationManager!.allowsBackgroundLocationUpdates = true
    _
  3. ビーコンと監視領域のレンジングを開始します。

    _locationManager!.startMonitoringForRegion(yourBeaconRegion)
    locationManager!.startRangingBeaconsInRegion(yourBeaconRegion)
    locationManager!.startUpdatingLocation()
    
    // Optionally for notifications
    UIApplication.sharedApplication().registerUserNotificationSettings(
        UIUserNotificationSettings(forTypes: .Alert, categories: nil))
    _
  4. CLLocationManagerDelegateを実装し、didEnterRegionstartRangingBeaconsInRegion()およびstartUpdatingLocation()メッセージの両方を送信し(オプションで通知も送信)、didExitRegionstopRangingBeaconsInRegion()およびstopUpdatingLocation()を設定します

このソリューションは機能しますが、Appleバッテリー消費と顧客のプライバシーのために推奨されません!

詳細はこちら https://community.estimote.com/hc/en-us/articles/203914068-Is-it-possible-to-use-beacon-ranging-in-the-background-

7
Teodor Ciuraru

ここでは、ビーコンの「レンジング」と地域の監視という2つの個別の操作を実行しています。バックグラウンドで領域を監視できますが、範囲ビーコンは監視できません。

したがって、locationManager:didRangeBeacons:inRegion:の実装はバックグラウンドで呼び出されません。代わりに、startMonitoringForRegionを呼び出すと、次のメソッドの1つまたはいくつかが呼び出されます。

– locationManager:didEnterRegion:
– locationManager:didExitRegion:
– locationManager:didDetermineState:forRegion:

これらはバックグラウンドで呼び出されます。その時点で、元のコードのようにローカル通知をトリガーできます。

2
James Frost

ビーコン地域に入ったときに通知を受け取りたいだけの場合、アプリは現在起動しているはずです。 iOSデバイスでiBeaconを実際にホストすることに関する懸念について知っている唯一の背景制限。その場合、アプリは物理的にフォアグラウンドで開いている必要があります。そのような状況では、単純にCoreBluetooth CBPeripheralManager実装を実行する方が良いでしょう。そうすれば、バックグラウンドでいくつかの広告能力が得られます。

1
Tommy Devoy