【发布时间】:2018-03-28 07:11:28
【问题描述】:
我想增加local notification的自定义铃声时间,但是
苹果说:
声音文件的长度必须小于 30 秒。如果声音文件超过 30 秒,则系统播放默认声音。
但我的声音文件是 5 分钟
我试过这样:
content.sound = [soundName:@"mycustomtone.aiff"];
content.time = [timeDuration: 300];
我知道 300 秒超过 30 秒,这不是定义时间的正确方法,因为没有通知声音时间的时间定义。
如果可能的话,帮助我将自定义声音的持续时间增加到 30 秒以上!
如果开发者愿意,我知道没有什么是不可能的!
这是我正在做的事情:
#import "ViewController.h"
@interface ViewController () {
NSUserDefaults *defaults;
}
@end
bool isGrantedNotificationAccess;
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
isGrantedNotificationAccess = false;
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
UNAuthorizationOptions options = UNAuthorizationOptionAlert+UNAuthorizationOptionSound;
[center requestAuthorizationWithOptions:options completionHandler:^(BOOL granted, NSError * _Nullable error) {
isGrantedNotificationAccess = granted;
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)notifyButton:(id)sender {
if (isGrantedNotificationAccess) {
NSLog(@"clicked");
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = @"Notification Title";
content.subtitle = @"Notification Subtitle";
content.body = @"Notification body";
content.sound = [UNNotificationSound soundNamed:@"alarm_clock_2015.aiff"];
content.timeDuration = 300;
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:60 repeats:YES];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"UYLocalNotification" content:content trigger:trigger];
[center addNotificationRequest:request withCompletionHandler:nil];
}
}
@end
【问题讨论】:
-
本地通知从哪里调用?你不能让通知的默认声音静音并创建一个不同的函数来播放声音吗?
-
@Egghead 我已经用代码更新了问题,我该如何定义函数你会回答吗?
标签: ios objective-c audio uilocalnotification duration