2012-04-07 12 views
0

私はUILocalNotificationのドキュメントを読んでいます。この例では、NSDateComponentsを使用して通知をスケジュールするために週、日、月などを設定しています。私は基本的に、特定の時間に毎日繰り返される目覚まし時計に似た何かをしようとしています。私はUIPickerViewで時間があり、私はその時間から自分のオブジェクトのNSDateを作成します。だから私は、時間をつかむと、私はそうのような通知をスケジュールしよう:NSDateを使ったUILocalNotification

NSDate *date = [dateFormatter dateFromString:s]; 
    NSCalendar *calender = [NSCalendar currentCalendar]; 
    NSLog(@"%@", s); 
    UILocalNotification *note = [[UILocalNotification alloc] init]; 
    note.alertAction = alarm.name; 
    note.alertBody = alarm.note; 
    note.fireDate = date; 
    note.timeZone = [[NSCalendar currentCalendar] timeZone]; 
    note.repeatInterval = NSDayCalendarUnit; 
          note.timeZone = [NSTimeZone systemTimeZone]; 

    [[UIApplication sharedApplication] scheduleLocalNotification:note]; 

私はそれを行うことができますか?またはNSDateComponentsを使用する必要がありますか?私のコードは現在、通知を発しませんし、この方法で通知を発行することさえ可能か、NSDateComponentsを使用する必要があるかどうかは疑問です。

また、NSDateComponentsを使用する必要がある場合、その日のアラームを設定できるように、現在の日を取得するにはどうすればいいのでしょうか?また、repeatIntervalが次の日に有効になると仮定しています。

ありがとうございました!

答えて

0

firedateが有効なNSDateである限り、通知が発生します。これは、Appタイムで私が使用するコード

 UILocalNotification *localNotification = [[UILocalNotification alloc] init]]; 

     localNotification.fireDate = [NSDate date]; 


     localNotification.timeZone = [NSTimeZone defaultTimeZone]; 
     localNotification.alertBody = @"some string"; 
     localNotification.repeatInterval = NSWeekCalendarUnit; 
     localNotification.repeatCalendar = [NSCalendar currentCalendar]; 
     localNotification.soundName = UILocalNotificationDefaultSoundName; 

     [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

あなたはfiredateに渡している日付が有効NSDateでチェックされます。あなたが使用しているタイムゾーンリピートコードが必要かどうか分かりません。問題を引き起こす可能性があります。

関連する問題