iOS PUSH notification type options? Alert vs Banne

2019-06-18 23:25发布

问题:

I have read through posts on here suggesting that the only way to make PUSH notifications appear as an alert instead of a banner is for the individual end user to change the Alert Style in the Notifications section of the app's Settings. What puzzles me is that there are apps out there that default to Alerts style without having to do this.

Is there a way to programatically set Alerts style through a dialog upon initial launch? I don't mind asking the user to confirm in a dialog. I just know since other apps don't require the user to manually go into settings to change the alert style, there has to be a different method of doing this...

I've got the following -

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
    return YES;
}

回答1:

Your app only has the rights to check for notification settings, you can never set or change notification types for a user.

When you query notification types the options are as follows

typedef NS_OPTIONS(NSUInteger, UIRemoteNotificationType) {
    UIRemoteNotificationTypeNone    = 0,
    UIRemoteNotificationTypeBadge   = 1 << 0,
    UIRemoteNotificationTypeSound   = 1 << 1,
    UIRemoteNotificationTypeAlert   = 1 << 2,
    UIRemoteNotificationTypeNewsstandContentAvailability = 1 << 3,
}

All you can find out from querying the push settings is wether or not the user has enabled alerts but not how they are displayed (banner vs alert).



回答2:

No this is not possible,you can't do it.

You can use this line to query the current settings for notification style:

UIRemoteNotificationType* enabledTypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];

You can check the enabledTypes and then instruct the user to change the notification style in the settings.