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

扶醉桌前 提交于 2019-12-08 04:44:38

问题


I am wondering how to send a Push Notification with NO sound.

From Apple's website:

The sound in this file is played as an alert. If the sound file doesn’t exist or default is specified as the value, the default alert sound is played.

This says that if I use "default" for the sound file or if I specify a sound file that does not exist, it will play the default alert sound.

But it does specifically state how to have no sound... If I just do not include a sound in the payload (leave it out), will this mean that there will be no sound played?

Thanks


回答1:


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.




回答2:


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.




回答3:


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

[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound]; 

just don't include UIRemoteNotificationTypeSound.



来源:https://stackoverflow.com/questions/9841600/ios-push-notifications-how-to-specify-alert-and-badge-with-no-sound

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