didRangeBeacons方法中的Fire Push Notification

时间:2014-07-17 09:13:45

标签: ios ios7 ibeacon estimote

我正在使用Estimote信标开发应用程序,所以我有三个信标一个用于Entry,第二个用于Exit,第三个用于messages.I想要基于邻近用户的火推送通知正在获得所以我得到推送通知但问题是那个它给出了多个相同的通知。 所以我使用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;
        }
    }

}

提前致谢。

1 个答案:

答案 0 :(得分:1)

试试这个,

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


        }
    }


}