Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在iOS中使用soundName发出通知时没有声音_Ios_Uilocalnotification_Localnotification - Fatal编程技术网

在iOS中使用soundName发出通知时没有声音

在iOS中使用soundName发出通知时没有声音,ios,uilocalnotification,localnotification,Ios,Uilocalnotification,Localnotification,我正在寻找在测试项目的Objective-C中使用soundName的通知上的工作声音,但这不起作用 我使用了答案中的代码,但声音不起作用,我不明白为什么:( 在我的ViewController.m中 - (IBAction)startLocalNotification:(id)sender { NSLog(@"startLocalNotification"); UILocalNotification *notification = [[UILocalNotification

我正在寻找在测试项目的Objective-C中使用soundName的通知上的工作声音,但这不起作用

我使用了答案中的代码,但声音不起作用,我不明白为什么:(

在我的ViewController.m中

- (IBAction)startLocalNotification:(id)sender {
    NSLog(@"startLocalNotification");

    UILocalNotification *notification = [[UILocalNotification alloc] init];
    notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
    notification.alertBody = @"This is local notification!";
    notification.timeZone = [NSTimeZone defaultTimeZone];
    notification.soundName = UILocalNotificationDefaultSoundName;
    notification.applicationIconBadgeNumber = 10;

    [[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
在我的AppDelegate中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){

        [application registerUserNotificationSettings:[UIUserNotificationSettings
                                                       settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|
                                                       UIUserNotificationTypeSound categories:nil]];
    }

    [launchOptions valueForKey:UIApplicationLaunchOptionsLocalNotificationKey];
    return YES;
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {


    UIAlertView *notificationAlert = [[UIAlertView alloc] initWithTitle:@"Notification"    message:@"This local notification"
                                                               delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

    [notificationAlert show];
}

确保你的应用程序在后台,这样你就可以听到声音,否则你就听不到声音了。

你能发布你的代码吗?以及你面临的错误?这将帮助你得到答案。编辑。而且我没有错:/Just sound不起作用,通知是允许的,声音也来自simulator/iPhone。因此,模拟器和设备都是如此无法播放声音?请确保设备上的振铃器已打开。