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);
}