本地通知声音不打? [英] Local Notification sound not playing?

查看:161
本文介绍了本地通知声音不打?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个问题,本地通知,他们不会播放声音。我用默认的和自定义一个显然是一个我想打,但没有测试!我看了和很多人面对这个问题,但他们没有一个解决方案,为我工作。

  UILocalNotification *本地 - (IBAction为)Dateaction:(ID)发送{    当地= [[UILocalNotification的alloc]初始化];
    local.timeZone = [NSTimeZone defaultTimeZone]
    local.alertBody = [的NSString stringWithFormat:@%@ Recuerda阙阙tienes:%@,[[NSUserDefaults的standardUserDefaults] objectForKey:@用户],[[NSUserDefaults的standardUserDefaults] objectForKey:@入选]];
    local.fireDate = [self.DatePicker日期];
   / *如果([self.userdefaults objectForKey:@声音] isEqualToString:@Sound1例子]){
        local.soundName = @sound1.caf
    }否则如果([self.userdefaults objectForKey:@声音] isEqualToString:@SOUND2]){
        local.soundName = @sound2.caf
    }否则如果([self.userdefaults objectForKey:@声音] isEqualToString:@Sound1例子]){
        local.soundName = @sound3.caf
    }其他{
        local.soundName = @sound1.caf
    } * /
    local.soundName = UILocalNotificationDefaultSoundName;
} - (IBAction为)switchChanged:(ID)发送{
如果(self.NotSwith.isOn == YES){
        [UIApplication的sharedApplication] scheduleLocalNotification:地方];
       }
}


解决方案

可能是一个相对简单的解决办法:你可以测试,如果它工作在模拟器?如果它工作在模拟器,而不是在设备我建议,确保静音开关没有打开(花4小时昨天搞清楚了这一点)。

I'm having this problem with the Local notifications, they are not playing the sound. I tested with the default one and the custom one that is obviously the one I want to play but nothing! I looked and a lot of people face this problem but none of their solutions worked for me.

UILocalNotification *local

- (IBAction)Dateaction:(id)sender {

    local = [[UILocalNotification alloc]init];
    local.timeZone = [NSTimeZone defaultTimeZone];
    local.alertBody = [NSString stringWithFormat:@"%@ Recuerda que tienes que: %@", [[NSUserDefaults standardUserDefaults] objectForKey:@"user"], [[NSUserDefaults standardUserDefaults] objectForKey:@"selected"]];
    local.fireDate = [self.DatePicker date];
   /* if ([[self.userdefaults objectForKey:@"sound"]isEqualToString:@"sound1"]) {
        local.soundName = @"sound1.caf";
    }else if([[self.userdefaults objectForKey:@"sound"]isEqualToString:@"sound2"]){
        local.soundName = @"sound2.caf";
    }else if([[self.userdefaults objectForKey:@"sound"]isEqualToString:@"sound1"]){
        local.soundName = @"sound3.caf";
    }else{
        local.soundName = @"sound1.caf";
    }*/
    local.soundName = UILocalNotificationDefaultSoundName;


}

- (IBAction)switchChanged:(id)sender {
if(self.NotSwith.isOn == YES){
        [[UIApplication sharedApplication] scheduleLocalNotification:local];


       }
}

解决方案

Might be a comparatively simple solution: can you test if it works in the Simulator? If it works in the Simulator and not in the device I'd suggest making sure the mute switch is not on (spent 4 hours yesterday figuring this out).

这篇关于本地通知声音不打?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆