到目前为止,我已经定义了我的班级mybeacon,ESTBeacon的扩展名,设置了一个属性," counter"在这种情况下。我想要"反击"作为一个全局变量,我是否以正确的方式对待财产?在我的ViewController中,我设置了一个名为" beaconsArray"的NSMutableArray属性,它代表了应用程序检测到的所有信标。
当我测量信标时,我会得到一组ESTBeacon对象。现在我不知道我是以正确的方式做到了,但是我试图检查更好的信标是在beaconsArray数组中,如果没有将它放入数组中,否则如果它已经只有增加"计数器"属性..
- (void)beaconManager:(ESTBeaconManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(ESTBeaconRegion *)region
{
for (ESTBeacon* beacon in beacons)
{
if (![self.beaconsArray containsObject:beacon ]) {
NSString *msg = [self get_message:[beacon.major unsignedShortValue]];
UILocalNotification *notification = [UILocalNotification new];
notification.alertBody = msg;
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
NSString *url = [self mysql_process:[beacon.major unsignedShortValue]];
[webView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:url]]];
//here convert object ESTBeacon into object mybeacon which has additional property and put the object into my array, which can grow only here.
} else if ([self.beaconsArray containsObject:beacon ]) {
//just increase a property counter by 1 and do something more or do nothing at all.
}
}
[manager stopRangingBeaconsInRegion:region];
}
答案 0 :(得分:0)
使用NSUserDefaults
存储全局变量,可以从整个应用程序的任何位置访问这些变量。
NSUserDefaults教程: http://code.tutsplus.com/tutorials/ios-sdk-working-with-nsuserdefaults--mobile-6039