cuốn sách gpt4 ai đã làm

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

In lại Tác giả: Walker 123 更新时间:2023-11-28 21:33:01 25 4
mua khóa gpt4 Nike

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

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

现在我无法实现第二个。

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

请帮忙!

câu trả lời hay nhất

假设您已在 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 文档 đây .

Kiểm tra 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/

25 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress