ios - Instagram 如何在不振动(新点赞)和振动(回复)的情况下向 iOS 设备发送推送通知?

标签 ios iphone push-notification apple-push-notifications vibration

我不明白如何通过两种方式向我的 iOS 应用程序发送推送通知:

  1. 振动 + 声音
  2. 没有振动和声音

现在我无法实现第二个。

一些信使使用第一种方式发送 DM 的推送通知,使用第二种方式进行群聊。 Instagram 也会使用第二种方式通知您新点赞。

请帮忙!

最佳答案

假设您已在 AppDelegate 中正确注册推送通知 (

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
     let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
     UIApplication.sharedApplication().registerUserNotificationSettings(settings)
     UIApplication.sharedApplication().registerForRemoteNotifications()

     return true
}

) 并将设备 token 存储在 func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData)

这一切都与您通过推送通知发送的有效负载有关。您会在远程通知负载上找到 Apple 文档 here .

查看 this SO thread一个很好的解释。

但为了快速解释:

一个 super 基本的 PN 有效载荷看起来像这样:

{
     "aps": {
          "alert": "Slide this alert to open my awesome app"
     }
}

1) 如果你想要作品(声音和振动),你会添加声音键 它看起来像这样:

{
    "aps" : {
         "alert" : "Slide this alert to open my awesome app",
         "sound" : "default"
    }
}

2) 根据我提供的第一个链接,如果您想让警报静音,您可以添加 content-available 键,这实际上是在后台启动您的应用程序,但本质上是一个沉默的 PN。它看起来像这样:

{
    "aps" : {
        "alert" : "Slide this alert to open my awesome app",
        "content-available": 1
    }
}

希望这对您有所帮助。

关于ios - Instagram 如何在不振动(新点赞)和振动(回复)的情况下向 iOS 设备发送推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35090016/

相关文章:

iphone - 服务器到客户端的消息传递能否依赖 APNS?

ios - 在尚未显示的 UIViewController 上预加载 UIWebView

ios - 是否可以为不同地区的iOS应用上传不同的元数据(应用信息,屏幕截图)

安卓 : How to bypass Do Not Disturb So that it plays notification audio in background

Flutter 本地通知每周重复通知

iPhone 应用程序在 iOS 4.0 上崩溃

objective-c - 访问有效的、未释放的对象时发生 EXC_BAD_ACCESS 错误

ios - 如何在 Xcode 5.1.1 或 Xcode 5 中获得与 iPhone 相同的 iPhone 模拟器 7.1 皮肤

ios - 如何将普通搜索栏更改为下图所示的搜索栏

iphone - 重新启动模拟器时添加的新视频文件将被删除