Reputation: 321
I want to increase the time of custom ring tone sound for local notification
but the
Apple says:
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.
But my sound file is of 5 minutes
I have tried in this way :
content.sound = [soundName:@"mycustomtone.aiff"];
content.time = [timeDuration: 300];
300 seconds are more than 30 seconds I know and this is not the right way to define time as there is no time definition for notification sound time.
Help me to increase the time duration of custom sound more than 30 seconds if possible!
I know nothing is impossible If a developer wants!
Here is what I am doing:
#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
Upvotes: 0
Views: 2171
Reputation: 7027
I'll give it a go, but I'm not able to test this code, but I'll give you a rough explanation how I would go about doing this.. (Don't know if this will work tho)
I would create a function like so:
-(void)playsound {
[[NSSound soundNamed:@"alarm_clock_2015"] play];
}
and call that function from your notifyButton IBAction
- (IBAction)notifyButton:(id)sender {
if (isGrantedNotificationAccess) {
NSLog(@"clicked");
[self playsound];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
//Mute the sound of this notification
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];
}
}
Upvotes: 0
Reputation: 3456
As you said :
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.
I would encourage you to take this into account since, even if you manage to trick and overcome the problem, Apple WILL reject your app.
that aside, 5 minutes is not a sound, it's a music, so to play app while the app is in the background, you must register as an audio app, and upon receiving a notification, use the AVAudioPlayer to play your file.
http://www.sagorin.org/ios-playing-audio-in-background-audio/
Upvotes: 3