# Inline in-apps in the iOS SDK

An inline slot is a view you place in your app's own layout, for example under a carousel on the home screen. Marketers fill it with a banner from an [inline block campaign](/product/messaging-channels/in-apps/send-in-apps/send-inline-in-apps/) in the Control Panel, using the same slot ID that you give the view. The SDK requests the slot's banner, draws it, sizes the slot to it, and reports shows, taps, and closes.

## Prerequisites

* Pushwoosh iOS SDK 7.3.1 or later, integrated as described in the [Basic integration guide](/developer/pushwoosh-sdk/ios-sdk/setting-up-pushwoosh-ios-sdk-7-0/basic-integration-guide/).
* The `PushwooshInApp` module, iOS 15.0 or later:
  * **Swift Package Manager:** add the `PushwooshInApp` product of the `Pushwoosh-XCFramework` package to your app target.
  * **CocoaPods:** add `pod 'PushwooshXCFramework/PushwooshInApp'`.

  Without the module, `Pushwoosh.inline` calls do nothing and only write a message to the log.

## Add a slot

Pick a slot ID for each place in the app that should show a banner, for example `home_promo`. Marketers enter the same ID in the campaign, letter case included, so send them the list of IDs and the screen each one is on.

In SwiftUI, put `PushwooshInlineSlot` where the banner should appear:

```swift
import SwiftUI
import PushwooshInApp

struct HomeView: View {
    var body: some View {
        ScrollView {
            DealsView()
            PushwooshInlineSlot(slotId: "home_promo")
            RecentlyViewedView()
        }
    }
}
```

In UIKit, add a `PushwooshInlineView`:

```swift
import PushwooshInApp

let slot = PushwooshInlineView(slotId: "home_promo")
stackView.addArrangedSubview(slot)
```

In a storyboard, set the view's custom class to `PushwooshInlineView` (module `PushwooshInApp`) and fill **Slot Id** in the Attributes inspector.

The slot is zero points high while it has no banner. When a banner arrives, the slot grows to the banner's height with an animation, and the views around it move aside. The banner takes the slot's width, so constrain the width and leave the height to the slot.

## How the SDK fills a slot

You don't need to call anything to load banners. The SDK requests:

* A slot the first time it appears on screen, together with other new slots that appear within 0.5 seconds.
* All slots it knows at the start of a session: the first launch, or a return after 30 minutes in the background.
* All slots again once the server confirms `setUserId` or `resetUserId`.

The SDK keeps the last banner of each slot on disk, so the slot shows it again after a relaunch without a network connection. An empty answer collapses the slot.

The SDK reports a show once at least half of the banner's height has stayed on screen for 0.3 seconds, once per banner version and user. For a user in the global control group, the slot stays empty. When the slot's place is on screen, the SDK reports a control show instead: a `control` event for the banner the user would have seen. Pushwoosh doesn't count it as a show.

When the user closes the banner, the slot collapses at once and then gets the next banner in its queue. The closed banner doesn't come back for this user until its campaign ends, or for 90 days if the campaign has no end date.

## Request slots manually

To refresh slots right away, for example after a purchase changes what the user should see, call `requestSlots` with up to 10 slot IDs:

```swift
Pushwoosh.inline.requestSlots(["home_promo", "cart_offer"]) { error in
    if let error {
        print("Inline slots were not refreshed: \(error)")
    }
}
```

Manual requests are limited to 5 per session start, then one every 3 minutes. A request over the limit, or one made before the server confirms a user change, fails without a network call, and the slots keep their banners.

## Follow slot events

Set `Pushwoosh.inline.delegate` to know when a slot changes, for example to log analytics events of your own. All callbacks are optional and arrive on the main thread:

```swift
import PushwooshInApp

final class InlineObserver: NSObject, PWInlineDelegate {
    func inlineSlot(_ slotId: String, didUpdate banner: PushwooshInlineBanner?) {
        // banner == nil: the slot became empty
    }

    func inlineSlot(_ slotId: String, didShow banner: PushwooshInlineBanner) {}

    func inlineSlot(_ slotId: String, didClick banner: PushwooshInlineBanner, elementId: String?) {
        // elementId: the data-pw-id of the tapped HTML element, nil for the banner itself
    }

    func inlineSlot(_ slotId: String, didDismiss banner: PushwooshInlineBanner) {}
}

let observer = InlineObserver()
Pushwoosh.inline.delegate = observer
```

## Match the app's theme

Banners follow the interface style of the view they're in (`.app`, the default). To change it, set `Pushwoosh.inline.colorScheme` to `.system` for the device setting, or to `.light` or `.dark`. Banners already on screen restyle at once.