【问题标题】:No sound playing on apple push notification iOS 8.1.3苹果推送通知iOS 8.1.3没有声音播放
【发布时间】:2015-01-30 04:46:03
【问题描述】:

我关注了这个tutorial,并按照它所说的那样设置了所有内容,以便在 iOS 上接收推送通知。

我在 Xcode 中设置了didFinishLaunchingWithOptions

if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) {
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound) categories:nil]];
    [application registerForRemoteNotifications];
} else {
    [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
}

我已注册(我能够获取 deviceToken)并且我可以在发送时从推送通知中获取消息,问题是我无法播放任何通知声音,我的 pusher.php 就像这个:

$body['aps'] = array(
    'alert' => $message,
    'sound' => "default" 
    );

我使用的是 iOS 8.1.3

【问题讨论】:

    标签: ios ios8 push-notification apple-push-notifications ios8.1


    【解决方案1】:

    我遇到了同样的问题,好像下面的代码已经过时了:

    if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
    {
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound |
                                                                                                    UIUserNotificationTypeAlert |
                                                                                                    UIUserNotificationTypeBadge) categories:nil]];
        [application registerForRemoteNotifications];
    }
    else
    {
        [application registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];
    }
    
    if (application) {
    
        application.applicationIconBadgeNumber = 0;
    
        if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
            [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|
                                                           UIUserNotificationTypeBadge|
                                                           UIUserNotificationTypeSound categories:nil]];
        }
    }
    return YES;}
    

    因为我只在应用程序中收到本地通知。即使在为此添加了正确的证书之后。 到目前为止,我没有找到任何帮助,因此最终向 Apple Developer Technical Support 发送了有关此问题的电子邮件。

    【讨论】:

    • 这个问题运气好吗?
    • 您好,这是我从 Apple 收到的回复:
    • 我正在回答您关于 Apple 推送通知服务的问题。 iOS 8.1.3 中没有任何 API 更改会影响推送通知。您是否只是从 iOS 7 SDK 升级?在 iOS 8 SDK 中,请求呈现用户通知的权限与注册推送通知是分开的。这仅影响使用 iOS 8 SDK 构建的应用程序。使用旧版 SDK 构建的应用应该仍能像以前一样工作。
    • 如果您在未相应更改代码的情况下迁移到 iOS 8 SDK,您将在控制台日志中收到一条消息,指出不再支持旧 API。查看为新 API 配置用户通知设置和注册远程通知。
    • 谢谢。顺便说一句,我发现了我的问题:我的应用通知在设置中被某种魔法禁用了:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-14
    • 1970-01-01
    • 1970-01-01
    • 2011-05-19
    • 2017-07-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多