iOS Push Notifications- How to specify alert and badge with NO sound?

∥☆過路亽.° 提交于 2019-12-08 06:38:23

If I just do not include a sound in the payload (leave it out), will this mean that there will be no sound played?

That's right. Just don't include sound in the payload. Or, don't even register for sound notification type if you're never going to want to play sounds.

You should configure your App to receive the type of PN that you wish to accept, there are three options:

  1. Display a short text message
  2. Play a brief sound
  3. Set a number in a badge on the app's icon

You may use these three in any combination that you see fit, now all you need to do in your App is to registerForRemoteNotificationTypes as follows:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
 
    // Let the device know we want to receive push notifications
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
        (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
 
    return YES;
}

Select the appropriate option(s) in your case, once the app starts and registers for Push Notifications, a message will popup asking the user whether or not to accept Push Notifications.

When registering for notifications you do something like this i'm guessing?

[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound]; 

just don't include UIRemoteNotificationTypeSound.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!