簡體   English   中英

iOS 8推送通知聲音不適用於此特定情況

[英]iOS 8 push notification sound does not work for this specific case

我在我的應用中為V1啟用了推送通知。 但是,在為推送通知注冊設備時,我沒有使用標志UIUserNotificationTypeSound

正如預期的那樣,發送推送通知時沒有播放任何聲音。 之后,當我添加此標志時,聲音僅播放新安裝,而不是為盡管重新注冊它們而使用V1的忠實用戶。

默認情況下,聲音在設置中保持關閉狀態。

我可以通過編程方式修復此問題嗎?

查看本教程,這是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:重置所有帳戶,使其工作就像剛剛安裝一樣。 可能的方法:核心數據,.plist文件等。

選項2:如果您通過重置應用程序中的所有數據(如新安裝的那樣)為您的應用程序發送修復此問題的更新,請為所有用戶播放聲音。 只需使用核心數據以編程方式重置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM