【问题标题】:iOS Push Notifications- How to specify alert and badge with NO sound?iOS 推送通知 - 如何在没有声音的情况下指定警报和徽章?
【发布时间】:2012-03-23 15:08:05
【问题描述】:

我想知道如何发送没有声音的推送通知。

来自Apple's website

此文件中的声音作为警报播放。如果声音文件 不存在或默认值被指定为值,默认警报 播放声音。

这表示如果我对声音文件使用“默认”,或者如果我指定一个不存在的声音文件,它将播放默认的警报声音。

但它确实明确说明了如何没有声音...如果我只是在有效载荷中不包含声音(将其排除在外),这是否意味着不会播放声音?

谢谢

【问题讨论】:

    标签: ios iphone ipad apple-push-notifications


    【解决方案1】:

    如果我只是在有效载荷中不包含声音(将其排除在外),这是否意味着不会播放声音?

    没错。只是不要在有效负载中包含sound。或者,如果您永远不想播放声音,甚至不要注册声音通知类型。

    【讨论】:

      【解决方案2】:

      您应该将您的应用配置为接收您希望接受的 PN 类型,共有三个选项:

      1. 显示短信
      2. 播放简短的声音
      3. 在应用图标的徽章中设置一个数字

      您可以在您认为合适的任何组合中使用这三个,现在您只需在您的应用程序中注册ForRemoteNotificationTypes,如下所示:

      - (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;
      }
      

      根据您的情况选择适当的选项,一旦应用启动并注册推送通知,将弹出一条消息询问用户是否接受推送通知。

      【讨论】:

        【解决方案3】:

        我猜你在注册通知时会做这样的事情?

        [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound]; 
        

        只是不包括 UIRemoteNotificationTypeSound。

        【讨论】:

          猜你喜欢
          • 2011-06-19
          • 1970-01-01
          • 1970-01-01
          • 2014-08-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-01-05
          • 1970-01-01
          相关资源
          最近更新 更多