目次
概要
WOVN.app 2.10.0 以降のバージョンをご利用の場合、プッシュ通知を翻訳できます。
利用したい場合は WOVN 側で設定が必要となるため、担当者、もしくはテクニカルサポートにお問い合わせください。
インフォメーション
利用状況によっては、契約の変更が発生する場合があります。
プッシュ通知を行うためのコードのセットアップをする
対象の SDK をご利用のお客様で WOVN 側の設定が完了している場合、以下の設定によりプッシュ通知の翻訳が行えます。
- サーバーで、すべてのプッシュ通知に "mutable_content" : true を追加してください。
- UNNotificationServiceExtension を拡張してカスタム ロジックを追加していない場合は、このドキュメントに従って拡張してください。
- UNNotificationServiceExtension とアプリは別のサンドボックスで実行されるため、App Groups を使用してデータを共有するためのブリッジを作成してください。
- group.io.wovn.workbox をアプリの App Groups に追加します。
- 手順 [2] で作成した UNNotificationServiceExtension の App Groups に group.io.wovn.workbox を追加します。
- group.io.wovn.workbox をアプリの App Groups に追加します。
- アプリと UNNotificationServiceExtension の両方で、アプリ グループ group.io.wovn.workbox について WOVN SDK に通知します。
- Wovn.setAppGroupIdentifier("group.io.wovn.workbox") をメイン アプリの AppDelegate に追加します。
注意
他の WOVN コードの前にこのメソッドを呼び出します。func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Some application code
Wovn.setAppGroupIdentifier("group.io.wovn.workbox")
// Some wovn code
// Some other application code
} - UNNotificationServiceExtension フォルダーの NoticeService.swift に次のコードを追加します。
import UserNotifications
ここまでの対応が完了しましたら、プッシュ通知を翻訳する準備は完了です。
import WOVNswift
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
Wovn.setAppGroupIdentifier("group.io.wovn.workbox", isMainApp: false)
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
let translatedContent = Wovn.translateNotificationContent(notiContent: bestAttemptContent)
contentHandler(translatedContent)
}
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
}
- Wovn.setAppGroupIdentifier("group.io.wovn.workbox") をメイン アプリの AppDelegate に追加します。
プッシュ通知の翻訳とテストをする
プッシュ通知を行うためのコードのセットアップが完了したら、プッシュ通知の翻訳を行います。
- 次のデータを使用して、Firebase Cloud Messaging 経由でデバイスにプッシュ通知を送信します。
{
"to": "{YOUR TESTING DEVICE FCM TOKEN}",
"notification": {
"mutable_content": true, // この行を忘れないでください
"title": "こんにちは",
"body": "素晴らしい日ですね!"
}
} - WOVN ダッシュボードの PushNotification 画面内に通知のタイトルと本文が登録されていることを確認します。
注意
初回時、テストデバイスは日本語で通知を受信します。 これは、WOVN にまだ翻訳された対訳が存在しないためです。 1 度プッシュ通知を行うと、WOVN にデータがレポートされます。 - タイトルと本文を翻訳し、[保存して公開] をクリックします。これにより、次回同じ通知を送信すると、通知はエンドユーザーの言語に翻訳されます。
ユーザーごとの動的情報を含むプッシュ通知を翻訳する
- 動的情報を通知のタイトルまたは本文に直接追加する代わりに、%{variable_name}% を使用して通知のデータ内に変数データを含めることができます。
{
"to": "{YOUR TESTING DEVICE FCM TOKEN}",
"notification": {
"mutable_content": true, // この行を忘れないでください
"title": "今月の請求書の準備ができました, %name%さん!",
"body": "今月は%amount%円です。 %date%までにお支払いください"
},
"data": {
"name": "John Doe",
"amount": "10000",
"date": "2023/12/12"
}
} - 指示に従ってプッシュ通知をテストします。 ユーザーデータを含むプッシュ通知は、ユーザーデータを WOVN ダッシュボードに報告せずに翻訳されます。
これにより、動的情報を含むプッシュ通知を送信しても、動的情報はそのまま表示され、翻訳対象のみが翻訳されます。
ローカルプッシュ通知を翻訳する
- Wovn.translateNotificationContent() を使用すると、ローカル プッシュ通知データを表示する前に翻訳できます。
var content = UNMutableNotificationContent()
content.title = "こんにちは%name%さん"
content.subtitle = "お金を払ってください.%amount%ドルです"
content.body = "期限内にお支払いをお願いいたします。%amount%ドルです"
content.userInfo.updateValue("Jone Doe", forKey: "name")
content.userInfo.updateValue("150", forKey: "amount")
content.userInfo.updateValue("2099/12/12", forKey: "date")
content.sound = UNNotificationSound.default
content = Wovn.translateNotificationContent(notiContent: content)
// Display local push notification code