![](/img/trans.png)
[英]Notify User about new update of application in app store as a alert and automatically install updated version in iPhone?
[英]How to notify the user with an alert sound every week from my application?
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];
以下是重復時間間隔的列表:
指定日歷單位,例如日和月。
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
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];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.