6

この質問がStackOverflowで何度も聞かれたことは知っていますが、iOSを初めて使用するため、アプリでアラームを設定できませんでしたか?私はこのチュートリアルに従ってアラームを設定しています:

iOSでUILocalNotificationを使用してリマインダーを設定します。

しかし、それは私にとってはうまくいかないようです。

毎日アラームを設定する必要があります5.00 PM。時刻の選択に日付ピッカーを使用できません。

4

4 に答える 4

9
  1. まずxib、(またはコード)で日付ピッカーモードを設定します:時間(デフォルトは日付と時刻)

  2. システムは、発火日が現在の日付であり、時刻がユーザーが選択した時刻であると想定します。繰り返し間隔を設定して機能するため、これは問題ではありません。私はそれをテストしました。

    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    [localNotif setFireDate:datePicker.date];
    [localNotif setRepeatInterval:NSDayCalendarUnit];
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    

PS:希望する分の最初の秒にアラームが鳴るように、クラスを0使用する秒数を設定することをお勧めします。NSDateComponentsあなたはチェックすることができます:

iOSのローカル通知。

これを行う方法について投稿したチュートリアル。

于 2012-08-07T17:59:48.633 に答える
1
+ (void)addLocalNotification:(int)year:(int)month:(int)day:(int)hours:(int)minutes:(int)seconds:(NSString*)alertSoundName:(NSString*)alertBody:(NSString*)actionButtonTitle:(NSString*)notificationID

パラメータを使用してこのメ​​ソッドを呼び出し、これを使用します

 + (void)addLocalNotification:(int)year:(int)month:(int)day:(int)hours:(int)minutes:(int)seconds:(NSString*)alertSoundName:(NSString*)alertBody:(NSString*)actionButtonTitle:(NSString*)notificationID {
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];

//set the notification date/time
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:day];

[dateComps setMonth:month];

[dateComps setYear:year];
[dateComps setHour:hours];

[dateComps setMinute:minutes];
[dateComps setSecond:seconds];

NSDate *notificationDate = [calendar dateFromComponents:dateComps];
[dateComps release];

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
    return;
localNotif.fireDate = notificationDate;
localNotif.timeZone = [NSTimeZone defaultTimeZone];

// Set notification message
localNotif.alertBody = alertBody;
// Title for the action button
localNotif.alertAction = actionButtonTitle;

localNotif.soundName = (alertSoundName == nil) ? UILocalNotificationDefaultSoundName : alertSoundName;

//use custom sound name or default one - look here to find out more: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html%23//apple_ref/doc/uid/TP40008194-CH103-SW13

localNotif.applicationIconBadgeNumber += 1; //increases the icon badge number

// Custom data - we're using them to identify the notification. comes in handy, in case we want to delete a specific one later
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:notificationID forKey:notificationID];
localNotif.userInfo = infoDict;

// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
}
于 2012-08-09T12:34:13.430 に答える
0

日付だけでなく時刻も変更できるように、日付ピッカーのスタイルを変更する必要がある場合があります。

于 2012-08-07T16:02:05.773 に答える
0

あなたはこれを試すことができます

UILocalNotification *todolistLocalNotification=[[UILocalNotification alloc]init];
[todolistLocalNotification setFireDate:[lodatepicker date]];
[todolistLocalNotification setAlertAction:@"Note list"];
[todolistLocalNotification setTimeZone:[NSTimeZone defaultTimeZone]];
[todolistLocalNotification setAlertBody:text_todolist];
[todolistLocalNotification setHasAction:YES];
于 2013-07-05T07:01:56.860 に答える