0

Bluetooth 4.0 BLE ハードウェア デバイスを開発しています。それは非常に簡単な方法で機能します。単一のサービス UUID と、0xFF (製造元固有のデータ) を含む追加の特別なペイロードをアドバタイズします。広告内のサービス UUID 以外の GATT プロファイル データは公開されません。

主なアイデアは、ユーザーがデバイスに近づくと、iPhone にメッセージが表示されるようにすることです。別の iBeacon プロトコルを作成しようとしているわけではありませんが、このアプリには特定の目的があります :)

アプリはフォアグラウンドで問題なく動作し、アプリがバックグラウンドで、特に電話をスリープ状態にしてから数分後に動作することもあります。UIBackgroundModes で「bluetooth-central」バックグラウンド モードを有効にしました。

アプリがバックグラウンドにあるときに Bluetooth ハードウェアが近くにあることにアプリケーションが気付かないことは非常によくあることであり、これが私が助けを必要としている主な問題です。何ヶ月もの間、私はこれが iOS のしくみだと思っていました。

Kensington Proximo Bluetooth Tracker Fob を購入しました。いくつかのテストの結果、このデバイスが本当に iPhone を起動できることがわかりました。私は方法を理解しようとしています。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSDictionary *options = @{ CBCentralManagerOptionRestoreIdentifierKey:@"myCentralManagerIdentifier", CBCentralManagerScanOptionAllowDuplicatesKey:[NSNumber numberWithBool:NO]};
    self.manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:options];
    return YES;
}

- (void)centralManager:(CBCentralManager *)central willRestoreState:(NSDictionary *)dict {
    NSLog(@"Restored, %@", dict);
}

- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
    NSDictionary *options = @{ CBCentralManagerOptionRestoreIdentifierKey:@"myCentralManagerIdentifier", CBCentralManagerScanOptionAllowDuplicatesKey:[NSNumber numberWithBool:NO]};

    if (self.manager.state == CBCentralManagerStatePoweredOn) {
        //Note, the actual UUID has been replaced below:
        [self.manager scanForPeripheralsWithServices:[NSArray arrayWithObject:[CBUUID UUIDWithString:@"12345678-1234-1234-1234-123456789012"]] options:options];
    }
}

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
    UILocalNotification* localNotification = [[UILocalNotification alloc] init];
    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
    localNotification.alertBody = @"It is close!";
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    localNotification.applicationIconBadgeNumber = 1;
    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
    NSLog(@"%@", advertisementData);
}
4

1 に答える 1

0

https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html を確認してください

つまり、バックグラウンドでは、アプリが以前にデバイスを検出したことがある場合、スキャン時にデバイスを検出しません。接続を試行することで、既知のデバイスに接続できます。Kensington Tracker がこれを行うと思います。

于 2014-10-10T20:16:54.490 に答える