This page shows you how to enableApp Checkin an Apple app, using[your customApp Checkprovider](https://firebase.google.com/docs/app-check/ios/custom-provider). When you enableApp Check, you help ensure that only your app can access your project's Firebase resources.

If you want to useApp Checkwith the built-in providers, see the docs for[App Checkwith App Attest](https://firebase.google.com/docs/app-check/ios/app-attest-provider)and[App Checkwith DeviceCheck](https://firebase.google.com/docs/app-check/ios/devicecheck-provider).

## Before you begin

- [Add Firebase to your Apple project](https://firebase.google.com/docs/ios/setup)if you haven't already done so.

- [Implement your customApp Checkprovider's server-side logic](https://firebase.google.com/docs/app-check/custom-provider).

## 1. Add theApp Checklibrary to your app

1. Add the dependency forApp Checkto your project's`Podfile`:

   ```
   pod 'FirebaseAppCheck'
   ```

   Or, alternatively, you can use[Swift Package Manager](https://firebase.google.com/docs/ios/swift-package-manager)instead.

   Also, make sure you're using the latest version of any Firebase service client libraries you depend on.
2. Run`pod install`and open the created`.xcworkspace`file.

## 2. Implement theApp Checkprotocols

First, you need to create classes that implement the`AppCheckProvider`and`AppCheckProviderFactory`protocols.

Your`AppCheckProvider`class must have a`getToken(completion:)`method, which collects whatever information your customApp Checkprovider requires as proof of authenticity, and sends it to your token acquisition service in exchange for anApp Checktoken. TheApp CheckSDK handles token caching, so always get a new token in your implementation of`getToken(completion:)`.  

### Swift

```swift
class YourCustomAppCheckProvider: NSObject, AppCheckProvider {
  var app: FirebaseApp

  init(withFirebaseApp app: FirebaseApp) {
    self.app = app
    super.init()
  }

  func getToken() async throws -> AppCheckToken {
    let getTokenTask = Task { () -> AppCheckToken in
      // ...

      // Create AppCheckToken object.
      let exp = Date(timeIntervalSince1970: expirationFromServer)
      let token = AppCheckToken(
        token: tokenFromServer,
        expirationDate: exp
      )

      if Date() > exp {
        throw NSError(domain: "ExampleError", code: 1, userInfo: nil)
      }

      return token
    }

    return try await getTokenTask.value
  }

}
```

### Objective-C

```objective-c
@interface YourCustomAppCheckProvider : NSObject <FIRAppCheckProvider>

@property FIRApp *app;

- (id)initWithApp:(FIRApp *)app;

@end

@implementation YourCustomAppCheckProvider

- (id)initWithApp:app {
    self = [super init];
    if (self) {
        self.app = app;
    }
    return self;
}

- (void)getTokenWithCompletion:(nonnull void (^)(FIRAppCheckToken * _Nullable,
                                                 NSError * _Nullable))handler {
    dispatch_async(dispatch_get_main_queue(), ^{
        // Logic to exchange proof of authenticity for an App Check token.
        // ...

        // Create FIRAppCheckToken object.
        NSTimeInterval exp = expirationFromServer;
        FIRAppCheckToken *token
            = [[FIRAppCheckToken alloc] initWithToken:tokenFromServer
                                       expirationDate:[NSDate dateWithTimeIntervalSince1970:exp]];

        // Pass the token or error to the completion handler.
        handler(token, nil);
    });
}

@end
```

Also, implement a`AppCheckProviderFactory`class that creates instances of your`AppCheckProvider`implementation:  

### Swift

```swift
class YourCustomAppCheckProviderFactory: NSObject, AppCheckProviderFactory {
  func createProvider(with app: FirebaseApp) -> AppCheckProvider? {
    return YourCustomAppCheckProvider(withFirebaseApp: app)
  }
}
```

### Objective-C

```objective-c
@interface YourCustomAppCheckProviderFactory : NSObject <FIRAppCheckProviderFactory>
@end

@implementation YourCustomAppCheckProviderFactory

- (nullable id<FIRAppCheckProvider>)createProviderWithApp:(FIRApp *)app {
    return [[YourCustomAppCheckProvider alloc] initWithApp:app];
}

@end
```

## 3. InitializeApp Check

Add the following initialization code to your app delegate or app initializer:  

### Swift

```swift
let providerFactory = YourAppCheckProviderFactory()
AppCheck.setAppCheckProviderFactory(providerFactory)

FirebaseApp.configure()
```

### Objective-C

```objective-c
YourAppCheckProviderFactory *providerFactory =
        [[YourAppCheckProviderFactory alloc] init];
[FIRAppCheck setAppCheckProviderFactory:providerFactory];

[FIRApp configure];
```

## Next steps

Once theApp Checklibrary is installed in your app, start distributing the updated app to your users.

The updated client app will begin sendingApp Checktokens along with every request it makes to Firebase, but Firebase products will not require the tokens to be valid until you enable enforcement in theApp Checksection of the Firebase console.

### Monitor metrics and enable enforcement

Before you enable enforcement, however, you should make sure that doing so won't disrupt your existing legitimate users. On the other hand, if you're seeing suspicious use of your app resources, you might want to enable enforcement sooner.

To help make this decision, you can look atApp Checkmetrics for the services you use:

- [MonitorApp Checkrequest metrics](https://firebase.google.com/docs/app-check/monitor-metrics)forFirebase AI Logic,Data Connect,Realtime Database,Cloud Firestore,Cloud Storage,Authentication, Google Identity for iOS, Maps JavaScript API, and Places API (New).
- [MonitorApp Checkrequest metrics forCloud Functions](https://firebase.google.com/docs/app-check/monitor-functions-metrics).

### EnableApp Checkenforcement

When you understand howApp Checkwill affect your users and you're ready to proceed, you can enableApp Checkenforcement:

- [EnableApp Checkenforcement](https://firebase.google.com/docs/app-check/enable-enforcement)forFirebase AI Logic,Data Connect,Realtime Database,Cloud Firestore,Cloud Storage,Authentication, Google Identity for iOS, Maps JavaScript API, and Places API (New).
- [EnableApp Checkenforcement forCloud Functions](https://firebase.google.com/docs/app-check/cloud-functions).

### UseApp Checkin debug environments

If, after you have registered your app forApp Check, you want to run your app in an environment thatApp Checkwould normally not classify as valid, such as a simulator during development, or from a continuous integration (CI) environment, you can create a debug build of your app that uses theApp Checkdebug provider instead of a real attestation provider.

See[UseApp Checkwith the debug provider on Apple platforms](https://firebase.google.com/docs/app-check/ios/debug-provider).