我正在開發藍牙4.0 BLE硬件設備。它的工作原理非常簡單。它通告單個服務UUID和一個包含0xFF(製造商特定數據)的附加特殊有效載荷。除了廣告中的服務UUID,它不會發布任何GATT個人資料數據。我的藍牙外設有時無法在後臺識別。 Kensington的Proximo作品
其主要思想是當用戶靠近設備時,應在iPhone上顯示消息。我不是想創建另一個iBeacon協議,但這個應用程序將有一個特定的目的:)
該應用程序工作完美,當在前臺,它也有時工作時,應用程序在後臺,特別是分鐘後,我把手機睡覺。我在UIBackgroundModes中啓用了「藍牙中央」背景模式。
當應用程序處於後臺並且這是我需要幫助的主要問題時,應用程序從不會注意到藍牙硬件靠近,這是非常常見的。幾個月來,我一直認爲這就是iOS的工作原理。
現在我已經購買了Kensington Proximo藍牙追蹤器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);
}
感謝您的回覆。我知道如果以前看過它,它不會檢測到該設備。但這不完全正確。如果我更改某些製造商特定數據,它會再次識別它。這有時運作良好,但有時候根本不運作,所以我需要知道如何像肯辛頓的Proximo那樣做這件事。 – 2014-10-10 21:15:08
我猜測Proximo軟件會嘗試連接(已知)設備。我沒有嘗試過,但我會,因爲我面臨着類似的挑戰。 – 2014-10-14 18:54:50