iOS通知无法播放声音

时间:2014-12-24 06:37:10

标签: notifications ios8

我已经在使用iOS 8的iOS应用中创建了一个通知。虽然注册了UIUserNotificationTypeSound并且指定了默认声音名称,但是正确显示了通知,但它没有播放声音。收到通知后如何播放声音?

注册UIUserNotificationTypeSound

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]

        return YES;
    }

设置默认声音名称

localNotif.soundName = UILocalNotificationDefaultSoundName;

1 个答案:

答案 0 :(得分:0)

我还没有测试过您的代码 但是与我的代码相比,我发现你没有调用[application registerForRemoteNotifications];方法

if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
{
    // iOS 8 Notifications
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

    [application registerForRemoteNotifications];
}

试试这个,我猜它会对你有帮助。