画像とビデオの追加(iOS) image-push

NOTE
このドキュメントは、iOSデバイスにのみ適用されます。

このドキュメントでは、Adobe Campaign Standard iOSのプッシュ通知から画像を表示する方法を説明します。

手順 1:プッシュ通知を設定する set-up-push

プッシュ通知は、Experience PlatformSDK でサポートされています。

プッシュ通知を受信するモバイルアプリケーションは、Adobe Campaignインターフェイスの管理者が設定する必要があります。

Adobe CampaignとAdobeMobile Services の両方を設定すると、モバイルアプリのデータをキャンペーンで使用できるようになります。 詳しくは、このページを参照してください。

Experience CloudSDK アプリケーションでプッシュ通知を送信するには、モバイルアプリをデータ収集 UI で設定し、Adobe Campaignで設定する必要があります。 詳しくは、このページを参照してください。

手順 2:Adobe Campaignでのプッシュ通知のカスタマイズ customize-push

Adobe Campaign では、プッシュ通知のデザイン中に一連の詳細設定オプションにアクセスして、プッシュ通知を微調整することができます。

  1. プッシュ通知を作成します。 詳しくは、このページを参照してください。

  2. プッシュ通知コンテンツページから、 Advanced options 」セクションに入力します。

  3. ファイルの URL を Rich media content URL フィールドに入力します。
    iOS 10 以降では、画像、gif、オーディオおよびビデオのファイルを挿入できます。

  4. プッシュ通知をプレビューして保存します。

手順 3:モバイルアプリケーションコードの適応 mobile-app-code

Adobe Campaignでプッシュ通知をカスタマイズした後、デバイスに画像を表示するようにモバイルアプリケーションを設定する必要があります。

NOTE
アプリケーションが Objective-C の場合は、次を参照してください。 ドキュメント.

アプリが Swift、次の手順に従います。

  1. を開きます。 Xcode プロジェクト。

  2. を Xcode プロジェクト、選択 File > New > Target.

  3. Notification Service Extension」を選択します。

  4. 以下を確認します。 NotificationService.swift ファイルクラスが作成されます。

  5. このクラスを編集し、デフォルトコンテンツを以下に置き換えます。
    これにより、アプリケーションは、画像 URL を持つ受信パラメーターを処理し、解析し、ローカルにコピーして、プッシュ通知から表示できます。

    code language-none
    import UserNotifications
    
    class NotificationService: UNNotificationServiceExtension {
    
    var contentHandler: ((UNNotificationContent) -> Void)?
    var bestAttemptContent: UNMutableNotificationContent?
    
    override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.contentHandler = contentHandler
        bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
    
        if let bestAttemptContent = bestAttemptContent {
            var urlString:String? = nil
            if let urlImageString = request.content.userInfo["media-attachment-url"] as? String {
                urlString = urlImageString
            }
    
            if urlString != nil, let fileUrl = URL(string: urlString!) {
                print("fileUrl: \(fileUrl)")
    
                // Download the attachment
                URLSession.shared.downloadTask(with: fileUrl) { (location, response, error) in
                    if let location = location {
                        // Move temporary file to remove .tmp extension
                        if (error == nil) {
                            let tmpDirectory = NSTemporaryDirectory()
                            let tmpFile = "file://".appending(tmpDirectory).appending(fileUrl.lastPathComponent)
                            let tmpUrl = URL(string: tmpFile)!
                            try! FileManager.default.moveItem(at: location, to: tmpUrl)
    
                            // Add the attachment to the notification content
                            if let attachment = try? UNNotificationAttachment(identifier: fileUrl.lastPathComponent, url: tmpUrl) {
                                bestAttemptContent.attachments = [attachment]
                                }
                        }
                        if(error != nil) {
                            print("Failed to download attachment: \(error.debugDescription)")
                        }
                    }
                    // Serve the notification content
                    contentHandler(bestAttemptContent)
                }.resume()
            }
        }
    }
    
    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)
        }
    }
    
    }
    

通知の送信中に、携帯電話が次のペイロードを受け取る必要があります。

画像 URL は、キー media-attachment-url にマッピングされます。 これは、画像をダウンロードして表示するためにアプリケーションコードの観点から処理する必要があるキーと値のペアです。

userInfo: [AnyHashable("media-attachment-url"): https://pbs.twimg.com/profile_images/876737835314950144/zPTs9b7o.jpg, AnyHashable("_dId"): 1de3ef93, AnyHashable("_mId"): h280a5, AnyHashable("aps"): {

    alert =     {

        body = "Message Body here";

        title = "This a push from Campaign";

    };

    badge = 1;

    "mutable-content" = 1;

}]

手順 4:プッシュの送信をテストする test-send-push

これで、上記の手順 2 で作成したアプリケーションと配信の構築をテストできます。 プッシュ通知の準備と送信について詳しくは、こちらを参照してください。 ページ.

recommendation-more-help
3ef63344-7f3d-48f9-85ed-02bf569c4fff