2013-03-02 43 views
0
UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
[localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:3600]]; 
[localNotification setAlertAction:@"Launch"]; 
[localNotification setAlertBody:[alertBodyField text]]; 
[localNotification setHasAction: YES]; 
[localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1]; 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
[alertNotification setHidden:NO]; 

回答

0

這裏重複間隔時間的列表:

指定曆法單位如日期和月份。

enum { 
    NSEraCalendarUnit = kCFCalendarUnitEra, 
    NSYearCalendarUnit = kCFCalendarUnitYear, 
    NSMonthCalendarUnit = kCFCalendarUnitMonth, 
    NSDayCalendarUnit = kCFCalendarUnitDay, 
    NSHourCalendarUnit = kCFCalendarUnitHour, 
    NSMinuteCalendarUnit = kCFCalendarUnitMinute, 
    NSSecondCalendarUnit = kCFCalendarUnitSecond, 
    NSWeekCalendarUnit = kCFCalendarUnitWeek, 
    NSWeekdayCalendarUnit = kCFCalendarUnitWeekday, 
    NSWeekdayOrdinalCalendarUnit = kCFCalendarUnitWeekdayOrdinal, 
    NSQuarterCalendarUnit = kCFCalendarUnitQuarter, 
    NSWeekOfMonthCalendarUnit = kCFCalendarUnitWeekOfMonth, 
    NSWeekOfYearCalendarUnit = kCFCalendarUnitWeekOfYear, 
    NSYearForWeekOfYearCalendarUnit = kCFCalendarUnitYearForWeekOfYear 
    NSCalendarCalendarUnit = (1 << 20), 
    NSTimeZoneCalendarUnit = (1 << 21), 
}; 
typedef NSUInteger NSCalendarUnit; 

你的情況:

您的重複間隔設置爲'NSWeekCalendarUnit'應該做的伎倆。它與原始通知在同一天和同一時間每週重複一次。

通知的一整套完善:

localNotification.soundName = UILocalNotificationDefaultSoundName; // Here you can also use custom sound . 

對於自定義音效

localNotification.soundName = @"alarm_sound.wav";// put name of sound file 
0
UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
[localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:3600]]; 
[localNotification setAlertAction:@"Launch"]; 
[localNotification setAlertBody:[alertBodyField text]]; 
[localNotification setHasAction: YES]; 

// change 
localNotification.repeatInterval = NSWeekCalendarUnit; // set the repeat interval 
localNotification.soundName = UILocalNotificationDefaultSoundName; // set alert sound 

[localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1]; 
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
[alertNotification setHidden:NO]; 
相關問題