2015-02-06 2 views
0

내 응용 프로그램에서 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 대리인이 호출되지 않습니다 ..

모든 경우 또는 다른 방법으로 알림 화재를 감지 할 수있는 방법은 그 통지가 화재를 감지 할 수있는 다음 내가 실행됩니다 내 삭제 방법. 어떤 도움이 을 감사

감사합니다

+0

죄송합니다, 즉 UILocalNotification' 작동하지 방법 '입니다. 앱이 백그라운드에서 실행되는 동안에는 코드를 실행할 수 없으므로이를 달성 할 수있는 다른 방법을 찾아야합니다. 백그라운드 실행은 iOS에서 까다로운 문제이며 불행히도 특정 시나리오에서만 사용됩니다. – nburk

+0

@nburk applicationWillEnterForeground 대리자에서 실행 된 UILocalnotification을 확인할 수 있습니까? –

+0

내가 원했던 일정과 함께이 문제에 부딪혔다. 가장 좋은 솔루션은 데이터 푸시 알림을하는 것으로 보였습니다. 일부 처리는 가능하지만 일정한 푸시를 제공하는 서비스를 찾기 좋은 가격으로 앱에서 구성 할 수는 있습니다. –

답변

0

앱이 일시 중단 된 상태 알림 화재가/종료 및 사용자가 알림을 탭하지 않은 경우 예, 당신이 바로, 당신은 알림의 정보를 알 수 없습니다 앱을 실행/활성화 할 수 있습니다.

유일한 방법은 앱을 실행할 때마다 시간을 계산하고 알림을 다시 예약하고 데이터베이스를 업데이트하는 것입니다. 밀리 초 계산에

:

NSInteger myMillisecond; //assume it exists 
const NSTimeInterval oneSecondAsMilliseconds = 1000.0; 
NSTimeInterval myTimeInterval = myMillisecond/oneSecondAsMilliseconds; 
NSDate *currentDate = [NSDate date]; 
NSTimeInterval currentTimeStamp = [currentDate timeIntervalSince1970]; 
if (myTimeInterval > currentTimeStamp) { 
    //myTimeInterval is a later time than now 
} 
+0

나는 전에이 생각이 떠올랐다. 나는 이미 이것을 시도했다. ..idea는 내가 설정 한 특정 시간의 알람을 밀리 세컨드로 변환하여 데이터베이스에 저장할 때마다 데이터베이스에서 가져온 알람 목록을 가져온다. 밀리 초 시간과 현재 시간을 비교해보십시오 ...하지만 밀리 초로 변환하여 현재 날짜와 시간과 비교할 수있는 방법을 모르겠습니다. 어떤 생각이 있습니까? –

+0

밀리 초 시간은 타임 스탬프를 의미합니까? – CarmeloS

+0

예, 안드로이드의 밀리 초에 나는 –

관련 문제