我正在使用Estimote信标开发应用程序,所以我有三个信标,一个用于输入,第二个用于退出,第三个用于消息。我想根据接近用户触发推送通知,所以我得到了推送通知,但问题是它给出了多个相同的通知。
所以我使用NSUserDefault来停止多个推送通知,但它也无法正常工作,所以我该如何停止这个问题。我还检查了本地通知,但它也给了我多个本地通知。
码:-
-(void)beaconManager:(ESTBeaconManager *)manager
didRangeBeacons:(NSArray *)beacons
inRegion:(ESTBeaconRegion *)region
{
if ([beacons count] == 0)
return;
ESTBeacon* beacon = [beacons firstObject];
int dist = [beacon.distance intValue];
if([region.identifier isEqualToString:BeaconIdentifier2]){
switch (beacon.proximity) {
case CLProximityUnknown:{
[[NSUserDefaults standardUserDefaults] setObject:@"FALSE" forKey:@"Far"];
[[NSUserDefaults standardUserDefaults] setObject:@"FALSE" forKey:@"Near"];
[[NSUserDefaults standardUserDefaults] setObject:@"FALSE" forKey:@"Immediate"];
[[NSUserDefaults standardUserDefaults] synchronize];
if([[[NSUserDefaults standardUserDefaults] valueForKey:@"Unknown"] isEqualToString:@"FALSE"])
{
[[NSUserDefaults standardUserDefaults] setObject:@"TRUE" forKey:@"Unknown"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"Call Unknown");
[self callPush];
}
}
break;
case CLProximityFar:{
[[NSUserDefaults standardUserDefaults] setObject:@"FALSE" forKey:@"Unknown"];
[[NSUserDefaults standardUserDefaults] setObject:@"FALSE" forKey:@"Near"];
[[NSUserDefaults standardUserDefaults] setObject:@"FALSE" forKey:@"Immediate"];
[[NSUserDefaults standardUserDefaults] synchronize];
if([[[NSUserDefaults standardUserDefaults] valueForKey:@"Far"] isEqualToString:@"FALSE"])
{
[[NSUserDefaults standardUserDefaults] setObject:@"TRUE" forKey:@"Far"];
[[NSUserDefaults standardUserDefaults] synchronize];
//Call webservice
[self callPush];
}
}
break;
case CLProximityNear:{
[[NSUserDefaults standardUserDefaults] setObject:@"FALSE" forKey:@"Unknown"];
[[NSUserDefaults standardUserDefaults] setObject:@"FALSE" forKey:@"Far"];
[[NSUserDefaults standardUserDefaults] setObject:@"FALSE" forKey:@"Immediate"];
[[NSUserDefaults standardUserDefaults] synchronize];
if([[[NSUserDefaults standardUserDefaults] valueForKey:@"Near"] isEqualToString: @"FALSE"])
{
[[NSUserDefaults standardUserDefaults] setObject:@"TRUE" forKey:@"Near"];
[[NSUserDefaults standardUserDefaults] synchronize];
//Call webservice
[self callPush];
}
}
break;
case CLProximityImmediate:{
[[NSUserDefaults standardUserDefaults] setObject:@"FALSE" forKey:@"Unknown"];
[[NSUserDefaults standardUserDefaults] setObject:@"FALSE" forKey:@"Far"];
[[NSUserDefaults standardUserDefaults] setObject:@"FALSE" forKey:@"Near"];
[[NSUserDefaults standardUserDefaults] synchronize];
if([[[NSUserDefaults standardUserDefaults] valueForKey:@"Immediate"] isEqualToString:@"FALSE"])
{
[[NSUserDefaults standardUserDefaults] setObject:@"TRUE" forKey:@"Immediate"];
[[NSUserDefaults standardUserDefaults] synchronize];
//Call webservice
[self callPush];
}
}
break;
}
}
}
提前致谢。
最佳答案
尝试这个,
BOOL isFar=TRUE;
- (void)locationManager:(CLLocationManager *)manager
didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region{
if (self.beaconRegion) {
if([beacons count] > 0)
{
//get closes beacon and find its major
CLBeacon *beacon = [beacons objectAtIndex:0];
switch (beacon.proximity)
{
case CLProximityUnknown:
break;
case CLProximityImmediate:
NSLog(@"Immediate");
if (isFar) {
isFar=false;
// Call WebService
}
break;
case CLProximityNear:
if (isFar) {
// Call WebService
}
isFar=false;
break;
case CLProximityFar:
NSLog(@"far");
if (!isFar) {
// call websercie
}
isFar=TRUE;
break;
default:
break;
}
}
}
}
关于ios - didRangeBeacons方法中的Fire Push Notification,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24799409/