Reputation: 6635
I enabled push notifications in my app for V1. I however did not use the flag UIUserNotificationTypeSound
while registering device for the push notification.
As expected no sound ever played when Push notifications were sent. Later when I added this flag the sound plays only for new installs and not for the loyal users who have been using V1 despite reregistering them.
The sound remains switched off by default in settings.
Can I fix this issue programmatically?
Upvotes: 3
Views: 510
Reputation: 1093
Check this Tutorial, It's for Today 2th of jan 2015
https://documentation.appboy.com/Enabling_Message_Channels/Push_Notifications/iOS
iOS 8 has changed notification registration in a non-backwards compatible way. While you need to support iOS 7 and 8 (and while apps built with the 8 SDK aren't accepted), you can check for the selectors you need and conditionally call them correctly for the running 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.
Header:
//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
Upvotes: 3
Reputation: 98
Below I have come up with two possible solutions.
Option 1: Reset all accounts so that they work as if just installed. Possible methods: Core Data, .plist file, etc.
Option 2: If you send out an update for your app that fixes this issue by resetting all data in the app as if it was newly installed, making the sound play for all users. Simply reset programmatically using core data.
Upvotes: 1