【发布时间】:2011-07-01 04:55:08
【问题描述】:
我正在尝试构建一个类似于当前在应用商店中的 Alarm Clock Pro 和 Nightstand 应用程序的闹钟。当到达闹钟时间(通常是第二天早上)时,这些应用程序中的每一个都能够播放超过 30 秒的闹钟声音。
我已经尝试了两种方法,但都没有成功:
方法一:
[self performSelector:@selector(playAlarm) withObject:nil afterDelay:myDouble];
方法2:
UILocalNotification *notif = [[cls alloc] init];
notif.fireDate =[datePicker date];//firedate;
notif.timeZone = [NSTimeZone systemTimeZone];
notif.alertBody = @"Time to wake up!";
NSString *SoundFileName=nil;
if([[[NSUserDefaults standardUserDefaults] objectForKey:@"ActualSoundFile"] isKindOfClass:[NSString class]])
SoundFileName=[[[NSString alloc]initWithString:[[NSUserDefaults standardUserDefaults]objectForKey:@"ActualSoundFile"]]autorelease];
else
SoundFileName=[[[NSString alloc] initWithString:@""] autorelease];
if([SoundFileName length]>1)
notif.soundName = [SoundFileName stringByAppendingString:@".wav"];
else
notif.soundName = UILocalNotificationDefaultSoundName;
notif.alertAction=@"Snooze";
notif.repeatCalendar=[NSCalendar currentCalendar];
notif.repeatInterval =NSDayCalendarUnit;
NSDictionary *userDict = [NSDictionary dictionaryWithObject:@"Alarm" forKey:kRemindMeNotificationDataKey];
notif.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];
有谁知道他们如何能够在 7 小时后循环播放闹钟?
【问题讨论】:
-
对于方法 2,这就是您的全部代码吗?在这一行之后你肯定需要更多代码。
-
@Ben - 刚刚添加了这两种方法。
标签: iphone objective-c ios