【发布时间】:2012-02-15 02:13:35
【问题描述】:
我是 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;
}
}
}
【问题讨论】:
-
in -(void)checkRegionEntered 我正在显示 localNotification 之类的
标签: iphone objective-c core-location cllocationmanager