## Install the latest version of Xcode

To use Nearby Connections in your project,
[Xcode](https://developer.apple.com/xcode/) **14.0 or later** is required.

## Add the Nearby Connections package to your project

Xcode comes with a built-in package manager. To add Nearby Connections to your
Xcode project, select **File** \> **Add Packages...** and search for
`google/nearby`. Then click **Add Package** and wait for the process to complete
(this may take a few minutes).

## Configure capabilities and entitlements

Depending on the mediums your application uses, configure the following capabilities in Xcode under **Signing \& Capabilities**:

- **Access Wi-Fi Information**: Required for accessing Wi-Fi network information and state.
- **Hotspot Configuration**: Required if your app supports high-speed data transfer via Wi-Fi Hotspot (allowing the iOS device to connect to a nearby peer hosting a Wi-Fi Hotspot).

These capabilities generate the corresponding keys in your app's `.entitlements` file:

    <key>com.apple.developer.networking.HotspotConfiguration</key>
    <true/>
    <key>com.apple.developer.networking.wifi-info</key>
    <true/>

> [!NOTE]
> **Note:** Ensure that your App ID in the Apple Developer Portal has the **Hotspot Configuration** capability enabled in its provisioning profile.

## Request access to protected resources

Nearby Connections needs access to Bluetooth, the local network, and location services to advertise, discover, establish high-speed connections, and transfer data. Provide a usage description for each resource needed in your app's `Info.plist`. If you don't, attempts to access the resource will fail and might cause your app to crash.

Required usage description keys:

- `NSBluetoothAlwaysUsageDescription`: Used to discover and advertise nearby devices over Bluetooth Low Energy.
- `NSLocalNetworkUsageDescription`: Used to discover and communicate with devices on the local network (Wi-Fi LAN).
- `NSLocationWhenInUseUsageDescription`: Required by iOS 13+ when connecting to high-speed Wi-Fi Hotspots (`NEHotspotConfigurationManager`).

In addition to usage description keys, an `NSBonjourServices` key with a list of the service types that will be browsed by the app must also be added for local network discovery. The only service type that must be added can be generated by taking the first 12 bytes of the `SHA-256` hash of your app's service ID.

You can use the following tool to automatically generate this value for you:
<iframe src="https://developers.devsite.google/frame/nearby/connections/swift/get-started_8ae2356bc61db41ef042e2da374b8c1ac2693db253f0169eaaeabf846a031f20.frame" class="framebox inherit-locale " allow="clipboard-write https://developers.devsite.google" allowfullscreen is-upgraded></iframe>

### Request runtime location authorization

When using Wi-Fi Hotspot for bandwidth upgrades, iOS requires runtime location authorization. Request location authorization early in your application lifecycle (for example, in your `App` initializer or `AppDelegate`):

    import CoreLocation

    class AppDelegate: NSObject, UIApplicationDelegate {
      private let locationManager = CLLocationManager()

      func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
      ) -> Bool {
        // Request location authorization required for Wi-Fi Hotspot operations
        locationManager.requestWhenInUseAuthorization()
        return true
      }
    }

> [!CAUTION]
> **Caution:** If location authorization is not requested or is in a `notDetermined` or `denied` state, iOS system services will silently reject Wi-Fi Hotspot join requests without displaying the system confirmation prompt to the user.