I want to display an image in the iPhone/Android push notification

Comentarios

2 comentarios

  • Martha Kooper

    To ensure that an image specified by an embed is displayed in push notifications on various devices, you need to consider the platform's notification system and its capabilities. Here are some guidelines for different platforms:

    iOS: When sending push notifications to iOS devices, you can include an "attachment" parameter in the payload. This attachment can be a URL pointing to the image you want to display. Ensure that the image is accessible over the internet. Use the "mutable-content" key in the payload with a value of 1 to allow modifying the notification content. Implement a Notification Service Extension on the client-side to handle the notification and download the image from the provided URL. You can then customize the notification content to include the downloaded image.

    Apple Watch: Apple Watch notifications are typically based on the notification content provided by the paired iPhone. Therefore, if the push notification is configured correctly for iOS, the same content, including the image, should be displayed on the Apple Watch.

    Android: Android push notifications can include an image by utilizing the "Big Picture Style" or "Big Image" notification style. Include an "image" parameter in the notification payload, which specifies the URL of the image you want to display. Make sure the image is publicly accessible. Use a library or framework for handling push notifications on Android, such as Firebase Cloud Messaging (FCM), and configure the notification style to display the image.

    It's important to note that the display of images in push notifications can vary depending on the device settings and the notification system's capabilities. Users may need to have their device settings configured to allow displaying images in push notifications. https://www.ballsportspro.com/what-is-a-dink-shot-in-pickleball/

    1
  • sneaker
    Hi Martha Kooper,
     
    Thank you for your very good advice the other day.
    I tried it on iOS.
    I tried to display the uploaded image file using the attachments parameter.
    Discord showed the image, but the push notification only showed the file name, not the image.
    Please let me know if you have any other advice.
    thank you.
     
    [PHP]
    $headers = array('Content-Type: multipart/form-data; charset=utf-8');

    $image = "/image_dir/test-image.png";
    $mimetype = mime_content_type($image);

    $message = [
        "content" => "test-content",
        "username" => "test-user",
        "avatar_url" => "https://????.com/avator_image.png",
      "file" => curl_file_create(realpath($image), $mimetype, 'upload_image.png'),
        "payload_json" => json_encode(
        array(
          "embeds" => array(
            array(
              "title" => "test-title",
              "url" => "https://????.com/test/page",
              "description" => "test-description",
              "image" => array(
              "url" => "attachment://upload_image.png",
              ),
              "author" => array(
                "name" => "test-author",
              ),
              "fields" => array(
                array(
                  "name" => "test-field1-name",
                  "value" => "test-field1-value"
                ),
              ),
              "color" => 0xff0000,
              "attachments" => array(
                array(
                  "id" => 0,
                  "description" => "test-attachment",
                "filename" => "upload_image.png",
                ),
              ),
            ),
          ),
        )
      )
    ];
    0

Iniciar sesión para dejar un comentario.