Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 更改已设置的UILocalNotification的声音名称_Iphone_Ios_Ipad_Alert_Uilocalnotification - Fatal编程技术网

Iphone 更改已设置的UILocalNotification的声音名称

Iphone 更改已设置的UILocalNotification的声音名称,iphone,ios,ipad,alert,uilocalnotification,Iphone,Ios,Ipad,Alert,Uilocalnotification,对于尚未创建的通知(新通知),它会被更改,但是对于已经创建的通知,以前的声音会保持不变 我试过: NSString *soundName = cell.titleLabel.text; NSArray *notifications = [[UIApplication sharedApplication] scheduledLocalNotifications]; for (UILocalNotification *notif in notifications) { notif.sou

对于尚未创建的通知(新通知),它会被更改,但是对于已经创建的通知,以前的声音会保持不变

我试过:

NSString *soundName = cell.titleLabel.text;

NSArray *notifications = [[UIApplication sharedApplication] scheduledLocalNotifications];

for (UILocalNotification *notif in notifications) {
    notif.soundName = [NSString stringWithFormat:@"%@.mp3", soundName];
}

但它不起作用…

您必须重新安排已安排的通知。但是,请确保删除先前计划的项目

NSArray *notifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
[[UIApplication sharedApplication] cancelAllLocalNotifications];

for (UILocalNotification *notif in notifications) {
    notif.soundName = [NSString stringWithFormat:@"%@.mp3", soundName]; 
    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
}