iOS 8推送通知声音不适用于此特定情况

时间:2014-12-19 02:15:25

标签: ios apple-push-notifications

我在我的应用中为V1启用了推送通知。但是,在为推送通知注册设备时,我没有使用标志UIUserNotificationTypeSound

正如预期的那样,发送推送通知时没有播放任何声音。后来当我添加这个标志时,声音只播放新的安装,而不是那些使用V1的忠实用户,尽管重新注册它们。

默认情况下,声音在设置中保持关闭状态。

我可以通过编程方式解决此问题吗?

2 个答案:

答案 0 :(得分:3)

查看本教程,今日2015年1月2日

https://documentation.appboy.com/Enabling_Message_Channels/Push_Notifications/iOS

iOS 8以非向后​​兼容的方式更改了通知注册。虽然您需要支持iOS 7和8(虽然不接受使用8 SDK构建的应用程序),但您可以检查所需的选择器并有条件地为正在运行的版本正确调用它们。

这是UIApplication上的一个类别,它将隐藏这个逻辑背后的干净界面,可以在Xcode 5和Xcode 6中使用。

部首:

//Call these from your application code for both iOS 7 and 8
//put this in the public header
@interface UIApplication (RemoteNotifications)

- (BOOL)pushNotificationsEnabled;
- (void)registerForPushNotifications;

@end
Implementation:

//these declarations are to quiet the compiler when using 7.x SDK
//put this interface in the implementation file of this category, so they are
//not visible to any other code.
@interface NSObject (IOS8)

- (BOOL)isRegisteredForRemoteNotifications;
- (void)registerForRemoteNotifications;

+ (id)settingsForTypes:(NSUInteger)types categories:(NSSet*)categories;
- (void)registerUserNotificationSettings:(id)settings;

@end

@implementation UIApplication (RemoteNotifications)

- (BOOL)pushNotificationsEnabled
{
    if ([self respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
    {
        return [self isRegisteredForRemoteNotifications];
    }
    else
    {
        return ([self enabledRemoteNotificationTypes] & UIRemoteNotificationTypeAlert);
    }
}

- (void)registerForPushNotifications
{
    if ([self respondsToSelector:@selector(registerForRemoteNotifications)])
    {
        [self registerForRemoteNotifications];

        Class uiUserNotificationSettings = NSClassFromString(@"UIUserNotificationSettings");

        //If you want to add other capabilities than just banner alerts, you'll need to grab their declarations from the iOS 8 SDK and define them in the same way.
        NSUInteger UIUserNotificationTypeAlert   = 1 << 2;

        id settings = [uiUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert categories:[NSSet set]];            
        [self registerUserNotificationSettings:settings];

    }
    else
    {
        [self registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert];
    }
}

@end

答案 1 :(得分:1)

下面我提出了两种可能的解决方案。

选项1: 重置所有帐户,使其工作就像刚安装一样。可能的方法:核心数据,.plist文件等。

选项2: 如果您通过重置应用中的所有数据(如新安装的那样)为您的应用发送修复此问题的更新,请为所有用户播放声音。只需使用核心数据以编程方式重置。