> ## Documentation Index
> Fetch the complete documentation index at: https://documentation.onesignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# iOS : Notifications push à carrousel d'images

> Comment implémenter un carrousel d'images dans les notifications push iOS OneSignal en utilisant Swift.

iOS fournit un protocole [UNNotificationContentExtension](https://developer.apple.com/documentation/usernotificationsui/unnotificationcontentextension?language=objc) comme point d'entrée pour une extension d'application de contenu de notification. Cela peut être utilisé pour afficher une interface personnalisée pour les notifications de votre application. Ce guide d'exemple explique comment l'utiliser pour créer un carrousel dans une notification iOS.

![](https://files.readme.io/8ba64c7-RPReplay_Final1606950566.gif)

Image montrant un carrousel dans une notification push

## 1. Ajouter une extension de contenu de notification

> [card]
>
> Dans Xcode, sélectionnez Fichier > Nouveau > Cible...

> [card]
>
> Sélectionnez "Notification Content Extension"

> [card]
>
> Confirmez la sélection dans la fenêtre qui apparaît

> [card]
>
> Sélectionnez activer pour déboguer

## 2. Ajouter du code à votre application

[Téléchargez OSNotificationContentExtension](https://github.com/jfishman1/OSNotificationContentExtension) depuis Github et remplacez le `OSNotificationContentExtension` dans votre projet Xcode par le même fichier de Github.

Vous devriez voir les fichiers suivants ajoutés :

![](https://mintcdn.com/onesignal/6v_cVPknFpo5qSVB/images/docs/0de83b8-Screen_Shot_2020-11-30_at_8.58.01_PM.png?fit=max\&auto=format\&n=6v_cVPknFpo5qSVB\&q=85\&s=ab382c7011a4481ab5cc91ce6d1a09cd)

Fichiers sous Content Extension

## 3. Définir votre catégorie de notification

Cet exemple [Déclare le type de notification actionnable](https://developer.apple.com/documentation/usernotifications/declaring_your_actionable_notification_types) dans le `didFinishLaunchingWithOptions` d'AppDelegate.swift.

```swift Swift theme={null}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    //START Authorize OS Notification Carousel Category
    if #available(iOS 10.0, *) {
        let options: UNAuthorizationOptions = [.alert]
        UNUserNotificationCenter.current().requestAuthorization(options: options) { (authorized, error) in
            if authorized {
                let categoryIdentifier = "OSNotificationCarousel"
                let carouselNext = UNNotificationAction(identifier: "OSNotificationCarousel.next", title: "👉", options: [])
                let carouselPrevious = UNNotificationAction(identifier: "OSNotificationCarousel.previous", title: "👈", options: [])
                let carouselCategory = UNNotificationCategory(identifier: categoryIdentifier, actions: [carouselNext, carouselPrevious], intentIdentifiers: [], options: [])
                UNUserNotificationCenter.current().setNotificationCategories([carouselCategory])
            }
        }
    }
    //END Authorize OS Notification Carousel Category

    return true
}
```

## 4. Envoyer votre notification push

Lors de l'[envoi de messages push](https://documentation.onesignal.com/docs/fr/push.md), vous pouvez définir la catégorie iOS et les données personnalisées.

### Catégorie iOS

Utilisez `OSNotificationCarousel` comme catégorie iOS :

> [tab] Tableau de bord
>
> Définissez sous "Paramètres de plateforme" > **Envoyer vers Apple iOS** > "Catégorie"
>
> ![](https://mintcdn.com/onesignal/6tscVAtiSqz353kV/images/docs/OSNotificationCarousel.png?fit=max\&auto=format\&n=6tscVAtiSqz353kV\&q=85\&s=2e0ff19d9f383aae03d510a34fc2c7fe)
>
> Options de plateforme iOS sur le tableau de bord OneSignal

> [tab] API
>
> Définissez avec le [paramètre API](https://documentation.onesignal.com/reference/push-notification.md) `ios_category`.

### Données personnalisées

OneSignal n'a pas d'option pour télécharger plusieurs images par notification.

Au lieu de cela, vous devez lister les URL d'images séparées par une virgule `,`

> [tab] Tableau de bord
>
> Définissez sous "Paramètres avancés" > "Données supplémentaires"
>
> Pour la "Clé", définissez `images` et pour la "Valeur", définissez la liste d'URL séparées par des virgules sans guillemets.
>
> ![](https://mintcdn.com/onesignal/4HyuQPBpu-4xjmQC/images/docs/d07200a-Screen_Shot_2020-11-30_at_9.19.59_PM.png?fit=max\&auto=format\&n=4HyuQPBpu-4xjmQC\&q=85\&s=1f4911116d4c3a944d1aa282d6566359)
>
> Exemple, copier-coller :
>
> ```text text theme={null}
> https://cdn.pixabay.com/photo/2015/12/01/20/28/road-1072823_960_720.jpg,https://cdn.pixabay.com/photo/2013/11/28/10/36/road-220058_960_720.jpg,https://cdn.pixabay.com/photo/2012/08/27/14/19/mountains-55067_960_720.png,https://cdn.pixabay.com/photo/2015/01/28/23/35/landscape-615429_960_720.jpg,https://cdn.pixabay.com/photo/2016/05/05/02/37/sunset-1373171_960_720.jpg
> ```

> [tab] API
>
> Utilisez le [paramètre API](https://documentation.onesignal.com/reference/push-notification.md) `data` comme ceci :
>
> ```json json theme={null}
> data: {
>   "images" : "https://cdn.pixabay.com/photo/2015/12/01/20/28/road-1072823_960_720.jpg,https://cdn.pixabay.com/photo/2013/11/28/10/36/road-220058_960_720.jpg,https://cdn.pixabay.com/photo/2012/08/27/14/19/mountains-55067_960_720.png,https://cdn.pixabay.com/photo/2015/01/28/23/35/landscape-615429_960_720.jpg,https://cdn.pixabay.com/photo/2016/05/05/02/37/sunset-1373171_960_720.jpg"
> }
> ```

### Envoyer la notification push

Une fois que vous recevez la notification push, vous devrez appuyer longuement ou balayer vers la gauche et cliquer sur "Afficher" pour développer la notification selon la version iOS.

### Lectures complémentaires

* [Documentation d'Apple pour déclarer vos types de notification actionnables](https://developer.apple.com/documentation/usernotifications/declaring_your_actionable_notification_types)
* [Article Medium utile par Ahmet Keskin](https://medium.com/nsistanbul/carousel-notification-in-ios-5a1e8239d786)

***


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.