2014-12-19 65 views
3

我在我的应用中为V1启用了推送通知。然而,我在注册推送通知设备时没有使用标志UIUserNotificationTypeSoundiOS 8推送通知声音不适用于此特定情况

正如预期的那样,发送推送通知时没有播放任何声音。之后,当我添加此标志时,声音仅适用于新安装,而不适用于尽管已经重新注册使用V1的忠实用户。

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

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

+1

经历过类似的情况。必须要求“忠实用户”重新启用它们。希望有一个比这更好的方法。 – Raptor 2014-12-19 02:20:08

回答

3

检查本教程中,它是2015年1月

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 
+0

虽然这是一个很好的解决方案,可能值得奖励,但如果您有抱怨的客户,他们也可以直接进入设置应用程序并启用声音,直到您提交修复程序。设置 - >通知 - >应用程序名称 - >声音 – 2015-01-06 20:47:13

+0

Hai,我遇到了同样的问题,但我无法使用此代码解决此问题,因为我不知道在我的项目中使用此代码的位置。你能解释我吗? – Manimaran 2015-01-29 11:04:27

1

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

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

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