2012-01-17 2 views
0

시간 기반 알림 응용 프로그램에서 작업 중입니다. 사용자는 자신의 미리 알림과 미리 알림 시간을 입력합니다. 문제는 현재 시간을 사용자 정의 시간과 지속적으로 비교하는 방법입니다. 모든 샘플 코드가 크게 도움이 될 것입니다. 왜냐하면 나는이 시점에 붙어 있기 때문이다.iPhone에서 시간 기반 알림 응용 프로그램 만들기

+0

스레드에서 도움을받을 수 있습니다. http://stackoverflow.com/questions/949416/how-to-compare-two-dates-in-objective-c – Ali3n

+0

나는이 방법을 지속적으로 실행하고 싶습니다. 메소드는 위치 관리자의 didupdatetolocation처럼 호출됩니다. –

답변

15

현재 시간과 사용자 정의 시간을 비교하는 것은 올바른 디자인 패턴이 아닙니다.

UIKit은 작업에 대한 더 높은 수준의 추상화 인 NSLocalNotification 객체를 제공합니다. 다음은

만들고은 선택된 시간에 로컬 알림을 예약 코드 싹둑입니다 : 또한

UILocalNotification *aNotification = [[UILocalNotification alloc] init]; 
    aNotification.fireDate = [NSDate date]; 
    aNotification.timeZone = [NSTimeZone defaultTimeZone]; 

    aNotification.alertBody = @"Notification triggered"; 
    aNotification.alertAction = @"Details"; 

    /* if you wish to pass additional parameters and arguments, you can fill an info dictionary and set it as userInfo property */ 
    //NSDictionary *infoDict = //fill it with a reference to an istance of NSDictionary; 
    //aNotification.userInfo = infoDict; 

    [[UIApplication sharedApplication] scheduleLocalNotification:aNotification]; 
    [aNotification release]; 

, AppDelegate에 시작시 정상 동안 두 지역의 통지에 응답하기 위해 설치해야 응용 프로그램의 런타임 (당신도 응용 프로그램을 통지 할 경우는 전경에) 다음 Apple Developer Documentation에서

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    UILocalNotification *aNotification = [launchOptions objectForKey: UIApplicationLaunchOptionsLocalNotificationKey]; 

    if (aNotification) { 
     //if we're here, than we have a local notification. Add the code to display it to the user 
    } 


    //... 
    //your applicationDidFinishLaunchingWithOptions code goes here 
    //... 


     [self.window makeKeyAndVisible]; 
    return YES; 
} 



- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { 

     //if we're here, than we have a local notification. Add the code to display it to the user 


} 

자세한 내용.

2

캘린더 일정과 매우 흡사하게 지정된 시간 동안 설정할 수 있습니다. 또는 EKEventKit

튜토리얼 local notifications과 함께 사용자 캘린더에 캘린더 이벤트를 추가 할 수 있습니다.

event kit에 대한 자습서.

관련 문제