내 응용 프로그램에서 Alarm 모듈을 작업 중입니다. 나는 사용자로부터 날짜와 시간 입력을 받아서 그 특정 시간에 이벤트를 내 앱에서 설정하는 코드를 개발했다. 또한 사용자가 설정 한 알람 목록을 표시하기 위해 로컬 데이터베이스에 정보를 저장합니다. (UILocalNotification 앱에 표시 할 때 난 DB에서 해당 항목을 삭제하는 데이터베이스 메소드를 호출 할) 특정 알람iOS의 UILocalNotification fire에서 사용자 정의 메서드 실행
나는이 방법으로 알림 설정을 실행하면
지금 내가 데이터베이스에서 항목을 삭제할
NSUserDefaults* preferences = [NSUserDefaults standardUserDefaults];
int notificationCount = [preferences integerForKey:@"notification_count"];
notificationCount++;
NSDate* final_date = [calendar dateFromComponents:final_Components];
UILocalNotification *localNotification = [[UILocalNotification alloc]init];
localNotification.fireDate = final_date;
localNotification.alertBody=titleTextField.text;localNotification.soundName = UILocalNotificationDefaultSoundName;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = 1;
NSDictionary* userInfoDic = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:notificationCount] forKey:@"notification_id"]; localNotification.userInfo = userInfoDic;
localNotification.repeatInterval = 0;
[[UIApplication sharedApplication]scheduleLocalNotification:localNotification];
[preferences setInteger:notificationCount forKey:@"notification_count"];
나는 내 문제가
-(void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSString *itemName = [notification.userInfo objectForKey:@"notification_id"];
NSLog(@"userInfo is %@",itemName);
databaseObject.deleteNotification(itemName)
}
는 "didReceiveLocalNotification"단지이 경우에는 전화를 위임 didReceiveLocalNotification을 사용
1) 사용자가 앱을 사용할 때 (전경에서 앱).
2) 통지가 표시되고 사용자가 클릭 응용 프로그램은 백그라운드 모드 및 알림에있을 때 통지
에 그러나 세번째 경우 표시 및 사용자 경우가 열려 있습니다 응용 프로그램이 직접 응용 프로그램을 클릭이다 통지 또는 두 번째 경우에 클릭하지 마십시오 아이콘 또는 사용자가 알림을 그때 didReceiveLocalNotification 대리인이 호출되지 않습니다 ..
모든 경우 또는 다른 방법으로 알림 화재를 감지 할 수있는 방법은 그 통지가 화재를 감지 할 수있는 다음 내가 실행됩니다 내 삭제 방법. 어떤 도움이 을 감사
감사합니다
죄송합니다, 즉 UILocalNotification' 작동하지 방법 '입니다. 앱이 백그라운드에서 실행되는 동안에는 코드를 실행할 수 없으므로이를 달성 할 수있는 다른 방법을 찾아야합니다. 백그라운드 실행은 iOS에서 까다로운 문제이며 불행히도 특정 시나리오에서만 사용됩니다. – nburk
@nburk applicationWillEnterForeground 대리자에서 실행 된 UILocalnotification을 확인할 수 있습니까? –
내가 원했던 일정과 함께이 문제에 부딪혔다. 가장 좋은 솔루션은 데이터 푸시 알림을하는 것으로 보였습니다. 일부 처리는 가능하지만 일정한 푸시를 제공하는 서비스를 찾기 좋은 가격으로 앱에서 구성 할 수는 있습니다. –