Я новичок в программировании iPhone. Я разработал одно приложение для проверки пользователя, введенного в определенный регион. Но мне нужно проверить в фоновом режиме. В фоновом режиме я проверяю, но проблема повторяется в предупреждениях UILocalNotification. Итак, как предотвратить повторные UILocalNotifications
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
NSLog(@"running in background ...");
[self checkRegionEntered];
CurrentlattitudeValue1 =newLocation.coordinate.latitude;
CurrentlongitudeValue1=newLocation.coordinate.longitude;
}
-(void)checkRegionEntered
{
if ([testRegion containsCoordinate:currentCoordinates])
{
[[UIApplication sharedApplication] cancelAllLocalNotifications];
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil)
{
UILocalNotification *notif = [[cls alloc] init];
NSDate *now = [NSDate date];
[notif setFireDate:now];
if([Obj.NotesGeo length])
[notif setAlertBody:Obj.NotesGeo];
else
{
[notif setAlertBody:[NSString stringWithFormat:@", you have arrived at %@",Obj.NameGeo]];
}
[notif setAlertAction:@"Launch"];
notif.soundName=[NSString stringWithFormat:@"%@.wav",Obj.Ringtone1];//[NSString stringWithFormat:@"%g",Obj.LatitudeGeo]
NSDictionary *userDict = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%f",Obj.LatitudeGeo] forKey:kRemindMeNotificationDataKey];
notif.userInfo = userDict;
}
}
}