gpt4 book ai didi

iphone - iOS 闹钟

转载 作者:行者123 更新时间:2023-12-03 19:52:18 25 4
gpt4 key购买 nike

我创建了一个简单的闹钟通知应用程序,通过它我可以获取实时信息、设置闹钟打开或关闭以及播放单音音频。但我需要播放应以类 VOID 开头的声音。

下面是代码:

获取并启动警报通知:

- (void)viewDidLoad {

[super viewDidLoad];

dateTimerPicker.date = [NSDate date];

}

- (void)presentMessage:(NSString *)message {

UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Hello!"
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];

}

- (void)scheduleLocalNotificationWithDate:(NSDate *)fireDate {

UILocalNotification *notification = [[UILocalNotification alloc]init];
notification.fireDate = fireDate;
notification.alertBody = @"Time to wake up!!";
notification.soundName = @"PhoneOld.mp3";
[self playPause];

[[UIApplication sharedApplication] scheduleLocalNotification:notification];

}

- (IBAction)alarmSetOn:(id)sender{

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone defaultTimeZone];
dateFormatter.timeStyle = NSDateFormatterShortStyle;
dateFormatter.dateStyle = NSDateFormatterShortStyle;

NSString *dateTimeString = [dateFormatter stringFromDate:dateTimerPicker.date];
NSLog(@"Alarm Set: %@", dateTimeString);


[self scheduleLocalNotificationWithDate:dateTimerPicker.date];
[self presentMessage:@"Alarm ON!"];


}

- (IBAction)alarmSetOff:(id)sender {
NSLog(@"Alarm Off");

[[UIApplication sharedApplication] cancelAllLocalNotifications];
[self presentMessage:@"Alarm OFF!"];
}

这是我的 VOID:

- (void)playPause {

RADAppDelegate *appDelegate = (RADAppDelegate *)[[UIApplication sharedApplication] delegate];

if (appDelegate.radiosound == 0){

[appDelegate.radiosound play];

} else {

[appDelegate.radiosound pause];

}

}

如果评级为 0,如何设置闹钟以开始播放 radio 声音,例如:

notification.soundName = [self playPause]; 

但我知道这是一个NSString

最佳答案

您不需要为预定通知分配声音名称,只需调用 playPause 方法并从通知中获取声音文件的名称,如下所示,只需将其分配给 NSString 并设置在 appDelegate 中为其添加属性并访问它来播放该文件。

AppDelegate.h

@property (nonatomic,strong) NSString *nsStr_soundFile;

AppDelegate.m

@synthesize nsStr_soundFile;

- (void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification {


//Give call to play sound method.

self.nsStr_soundFile=notification.soundName;
VOID *obj=[VOID alloc]init];
[obj playPause];

}

关于iphone - iOS 闹钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17922495/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com