> ## Documentation Index
> Fetch the complete documentation index at: https://radarlabs-jasonliu-test.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Showing a notification when a user enters a geofence

In this tutorial, we show you how to use the Radar [iOS SDK](https://docs.radar.com/sdk) and [geofences](https://docs.radar.com/geofences) to show a notification when a user enters a geofence.

In this example, we show local notifications on iOS using [RadarDelegate](https://docs.radar.com/sdk/ios#delegate). Alternatively, you could show local notifications on Android using [RadarReceiver](https://docs.radar.com/sdk/android#receiver), or send remote push notifications using a [webhook](https://docs.radar.com/integrations) or [integrations](https://docs.radar.com/integrations) with platforms like OneSignal, Braze, and Airship.

## Languages used

* Swift

## Features used

* [iOS SDK](/sdk/ios)
* [Geofences](/geofencing/geofences)

## Steps

<Steps>
  <Step title="Sign up for Radar">
    If you haven't already, sign up for Radar to get your API key. You can create up to 1,000 geofences and make up to 100,000 API requests per month for free.

    [**Get API keys**](https://radar.com/signup)
  </Step>

  <Step title="Import geofences">
    On the [Geofences page](https://dashboard.radar.com/geofencing/geofences), create a geofence.
  </Step>

  <Step title="Install the Radar iOS SDK">
    Initialize the SDK in your `AppDelegate` class with your publishable API key. Make your `AppDelegate` implement `RadarDelegate`. Finally, [request location permissions](/sdk/ios#request-permissions) and start tracking:

    ```swift theme={null}
    import UIKit
    import RadarSDK

    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate, RadarDelegate {

        let locationManager = CLLocationManager()

        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
            Radar.initialize(publishableKey: "prj_test_pk_...")
            Radar.setDelegate(self)

            self.locationManager.requestAlwaysAuthorization()

            Radar.startTracking(trackingOptions: RadarTrackingOptions.presetResponsive)

            return true
        }

    }
    ```
  </Step>

  <Step title="Listen for events">
    Implement `didReceiveEvents:user:` to listen for geofence entry events and show notifications:

    ```swift theme={null}
    func didReceiveEvents(_ events: [RadarEvent], user: RadarUser) {
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { (granted, error) in
        if granted {
            for event in events {
                if event.type == .userEnteredGeofence {
                    let content = UNMutableNotificationContent()
                    content.body = "You entered a geofence!"
                    content.sound = UNNotificationSound.default
                    content.categoryIdentifier = "geofence"

                    let request = UNNotificationRequest(identifier: event._id, content: content, trigger: nil)
                    UNUserNotificationCenter.current().add(request, withCompletionHandler: { (_) in })
                }
            }
        }
    }
    ```
  </Step>
</Steps>

## Sample code

```swift theme={null}
// AppDelegate.swift

import UIKit
import RadarSDK

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, RadarDelegate {

    let locationManager = CLLocationManager()

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        Radar.initialize(publishableKey: "prj_test_pk_...")
        Radar.setDelegate(self)

        self.locationManager.requestAlwaysAuthorization()

        Radar.startTracking(trackingOptions: RadarTrackingOptions.presetResponsive)

        return true
    }

    func didReceiveEvents(_ events: [RadarEvent], user: RadarUser) {
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { (granted, error) in
        if granted {
            for event in events {
                if event.type == .userEnteredGeofence {
                    let content = UNMutableNotificationContent()
                    content.body = "You entered a geofence!"
                    content.sound = UNNotificationSound.default
                    content.categoryIdentifier = "geofence"

                    let request = UNNotificationRequest(identifier: event._id, content: content, trigger: nil)
                    UNUserNotificationCenter.current().add(request, withCompletionHandler: { (_) in })
                }
            }
        }
    }
}
```

## Support

Have questions or feedback on this documentation? Let us know! Contact us at [radar.com/support](https://radar.com/support).
