OneSignal Отправить push -уведомление пользователям, когда они получат новое следующее SwiftIOS

Программируем под IOS
Ответить Пред. темаСлед. тема
Anonymous
 OneSignal Отправить push -уведомление пользователям, когда они получат новое следующее Swift

Сообщение Anonymous »

Я новый разработчик и настроил OneSignal с моим приложением для iOS, а моя база данных - Firebase, однако я изо всех сил пытаюсь найти, как отправить push -уведомления определенным пользователям, когда они получат новое следствие, может ли кто -нибудь помочь
Это коды: < /p>
static func follow(uid: String) async throws {
guard let currentUid = Auth.auth().currentUser?.uid else { return }

let userFollowingDoc = FirestoreConstants.FollowingCollection.document(currentUid).collection("user-following").document(uid)
let userFollowersDoc = FirestoreConstants.FollowersCollection.document(uid).collection("user-followers").document(currentUid)

try await Firestore.firestore().runTransaction { transaction, errorPointer in
do {
let userDoc = FirestoreConstants.UserCollection.document(uid)
let currentUserDoc = FirestoreConstants.UserCollection.document(currentUid)

transaction.updateData(["stats.followers": FieldValue.increment(Int64(1))], forDocument: userDoc)
transaction.updateData(["stats.following": FieldValue.increment(Int64(1))], forDocument: currentUserDoc)

transaction.setData([:], forDocument: userFollowingDoc)
transaction.setData([:], forDocument: userFollowersDoc)
} catch {
errorPointer?.pointee = error as NSError
return nil
}
return nil
}
}

import UserNotifications
import OneSignalExtension

class NotificationService: UNNotificationServiceExtension {

var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
var receivedRequest: UNNotificationRequest!

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
self.receivedRequest = request
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)

guard let bestAttemptContent = bestAttemptContent else { return }

// Configure the notification content
OneSignalExtension.didReceiveNotificationExtensionRequest(
self.receivedRequest,
with: bestAttemptContent,
withContentHandler: contentHandler
)

// Add custom notification handling if needed
if let userInfo = bestAttemptContent.userInfo as? [String: Any] {
// Example: Add a custom category for follow notifications
if let notificationType = userInfo["type"] as? String, notificationType == "follow" {
bestAttemptContent.categoryIdentifier = "FOLLOW_CATEGORY"
}

// Example: Modify the notification body based on the type
if let senderName = userInfo["senderName"] as? String {
bestAttemptContent.body = "\(senderName) \(bestAttemptContent.body)"
}
}

// Add a custom sound
bestAttemptContent.sound = UNNotificationSound.default
}

override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
guard let contentHandler = contentHandler,
let bestAttemptContent = bestAttemptContent else { return }

// Use this as an opportunity to deliver your "best attempt" at modified content
OneSignalExtension.serviceExtensionTimeWillExpireRequest(
self.receivedRequest,
with: bestAttemptContent
)

contentHandler(bestAttemptContent)
}
}


Подробнее здесь: https://stackoverflow.com/questions/794 ... llow-swift
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Отправить push -уведомление многим пользователям через Python
    Anonymous » » в форуме Python
    0 Ответы
    10 Просмотры
    Последнее сообщение Anonymous
  • Неверный исполняемый файл. Исполняемый файл appname.app/Frameworks/OneSignal.framework/OneSignal содержит битовый код. (
    Anonymous » » в форуме IOS
    0 Ответы
    57 Просмотры
    Последнее сообщение Anonymous
  • Нет версий com.onesignal: OneSignal - это ошибка оценки
    Anonymous » » в форуме Android
    0 Ответы
    1 Просмотры
    Последнее сообщение Anonymous
  • Onesignal Web Push-уведомление во Frappe
    Anonymous » » в форуме Python
    0 Ответы
    15 Просмотры
    Последнее сообщение Anonymous
  • Как отладить удаленное push-уведомление, когда приложение не запущено и нажмите push-уведомление?
    Anonymous » » в форуме IOS
    0 Ответы
    136 Просмотры
    Последнее сообщение Anonymous

Вернуться в «IOS»