简体   繁体   English

声音未在UILocal通知中播放

[英]sound not playing in UILocal notification

Hello i set the name of sound to UILocal notification but its not playing it correct but sound is not ringing when notification is fired as well as default sound also not playing. 您好,我将声音名称设置为UILocal通知,但未正确播放,但在触发通知以及默认声音也未播放时声音未响起。 song formate is .waw which is supported by apple.. 歌曲格式为.waw,由Apple支持。

Source code: 源代码:

[[UIApplication sharedApplication] cancelAllLocalNotifications];  
UILocalNotification *notification=[[UILocalNotification alloc]init];  
notification.fireDate=[NSDate dateWithTimeIntervalSinceNow:100];  
notification.alertBody=@"Time to wake up";  
notification.alertAction = @"Snooze";  
notification.soundName=@"Guitar.wav";  
//notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber = 1;  
[[UIApplication sharedApplication] scheduleLocalNotification:notification];  

Try this two way and get which is for you ? 尝试这两种方法并获得适合您的?

UILocalNotification *localNotification = [[UILocalNotification alloc] init];

    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];

    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    localNotification.alertBody = @"You have long time to care your......";
    localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber]+1;
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    localNotification.repeatInterval = kCFCalendarUnitMinute;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
    [localNotification release];
    localNotification = nil;

////////////OR/////////////// ////////////要么///////////////

UILocalNotification *localNotification = [[UILocalNotification alloc]init];

   // Set the notification time.
    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];

   // You can specify the alarm sound here.
   localNotification.soundName = UILocalNotificationDefaultSoundName;
   //OR
   localNotification.soundName = @"sound.caf";

   // Set the alertbody of the notification here.
    localNotification.alertBody = @"Test Alert";

   // Create the buttons on the notification alertview.
    localNotification.alertAction = @"View";

   // You can also specify custom dictionary to store informations
    NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"alarm#2" forKey:@"notifiKey"];
    localNotification.userInfo = infoDict;

    //Repeat the notification.
    localNotification.repeatInterval = NSDayCalendarUnit;

// Schedule the notification
[[UIApplication sharedApplication]scheduleLocalNotification:localNotification];

Try to convert your sound to caf format int terminal with command: 尝试使用以下命令将声音转换为caf格式的int终端:

afconvert -f caff -d LEI16@44100 -c 1 in.wav out.caf

And make sure the sound is under 30 sec. 并确保声音在30秒以下。

我在iPhone的通知中心发现了我的问题的解决方案,我的应用程序声音已关闭,因此我只打开它并正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM