我正在使用新的iOS7 API iOS應用程序:iBeacon。iOS - 使用iBeacons觸發事件
我只是想,當我發現一個給定的接近,這裏立即觸發事件(出4,其他是近,遠和未知)。
當我在我的iPhone 4S上構建我的應用程序時,它可以工作。所以我可以說我做,但因爲我很新到iOS,我不知道在所有如果我的實現不管怎樣正確或者,即使不是這種情況,安全更糟。
我基本上在我的視圖控制器(objective-c class)中實現了我的事件,並在locationManager方法中調用它,其中信標得到了範圍。如果你想看看它是如何發展的,我拿了示例應用AirLocate中給出的代碼。
我的事件簡單地調用另一個視圖(爲了給獲得一些新的特點在那個特定的觀點,只有當你在緊鄰我的信標)。我認爲這是智能,因爲每次我的信標得到範圍,if條件也運行,如果它是真的,我的事件被調用。
下面是我的,如果條件是在的LocationManager方法的末尾:
//Beacons ranging method from Apple until here.
//My code following the sample code.
CLBeacon *beacon = [[CLBeacon alloc] init];
beacon = [beacons lastObject];
if (beacon.proximity == CLProximityImmediate) {
[self immediateDetection];
}
//End of the method here, which would be closed by the last "}"
這裏是我的小方法/事件:
- (void)immediateDetection
{
NSString *storyboardName = @"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"HueSwitch"];
//call another view
[self presentViewController:viewController animated:YES completion:nil];
}
正如我所說的,它的工作原理罰款在我的iPhone,但我無法知道它是否是一個不行。
所以,我只是傻,它似乎是所有罰款或沒有我的代碼有一些嚴重的安全性或穩定性問題?
謝謝。
只有一個建議:爲生產非常頻繁委託調用,你需要檢查屏幕上已有的「立即」視圖並且不再顯示 – sage444
'CLBeacon * beacon = [[CLBeacon alloc] init];' - 此行不需要 – sage444
好的,下列是否正確?而不是2個第一代碼行,我只有那一個: 'CLBeacon * beacon = [beacon lastObject];' – ySiggen