私はiPhoneプログラミングを初めて利用しています。ユーザーが特定の地域に入ったことを確認するアプリケーションを開発しました。問題はUILocalNotification警告を繰り返すことです。 それでは、どのようこれが役立つかもしれロケーションマネージャを使用したローカル通知の表示中にアプリがバックグラウンドにある
- (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;
}
}
}
- (ボイド)私はあなたがバックグラウンドにしているか否かを追跡するためにBOOLを作成する必要はありません –