声音没有在本地通知中播放

时间:2014-03-05 06:35:17

标签: ios iphone

您好我将声音的名称设置为UILocal通知,但它没有正确播放,但是在通知被触发时声音没有响起,默认声音也没有播放。 song formate是.waw,由苹果支持..

源代码:

[[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];  

3 个答案:

答案 0 :(得分:0)

尝试这两种方式并找到适合您的方式?

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];

答案 1 :(得分:0)

尝试使用命令将声音转换为caf格式的int终端:

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

确保声音低于30秒。

答案 2 :(得分:0)

我在iphone的通知中心找到了我的问题的解决方案我的应用声音已关闭,所以我只是打开它并运行它。

相关问题