IOS 8 push not beep not working for this specific case

I have enabled push notifications in my app for V1. However, I didn't use the flag UIUserNotificationTypeSound

when registering the device for push notification.

As expected, no sound was played when sending push notifications. Later, when I added this flag, the sound is only played for new installations, not for loyal users who have used V1 despite their re-registration.

The sound is disabled by default in the settings.

Can I fix this problem programmatically?

+3


source to share


2 answers


Check this tutorial, it is for today 2nd Jan 2015

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

iOS 8 changed notification registrations to be compliant open loop. While you need to support iOS 7 and 8 (and while apps built with SDK 8 are not accepted), you can check which selector you need and conditionally name them correctly for the current version.



Here's a category on UIApplication that will hide this logic behind a clean interface for you that will work in both Xcode 5 and Xcode 6.

Title:

//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

      

+3


source


Below I have come up with two possible solutions.

Option 1: Reset all accounts so that they work as if they were installed. Possible methods: Master data, .plist file, etc.



Option 2: If you send an update for your app that fixes this issue by resetting all data in the app as if it were reinstalled, the audio sounds to all users. Just reset programmatically using the master data.

+1


source







All Articles