gpt4 book ai didi

ios - 在目标ios中增加自定义本地通知声音的时间

转载 作者:行者123 更新时间:2023-12-03 00:13:16 25 4
gpt4 key购买 nike

我想增加local notification的自定义铃声的时间,但是

苹果说:

声音文件的长度必须少于30秒。如果声音文件超过30秒,则系统将播放默认声音。

Here is the documentation

但是我的声音文件只有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

最佳答案

如你所说 :

Sound files must be less than 30 seconds in length. If the sound file is longer than 30 seconds, the system plays the default sound instead.



我鼓励您考虑到这一点,因为即使您设法欺骗并克服了该问题,Apple也会拒绝您的应用程序。

另外,5分钟不是声音,而是音乐,因此要在后台运行该应用程序,您必须注册为音频应用程序,并在收到通知后,使用AVAudioPlayer播放文件。

http://www.sagorin.org/ios-playing-audio-in-background-audio/

关于ios - 在目标ios中增加自定义本地通知声音的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49528228/

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