# Implement Application Delegate

To allow the iOS SDK to respond to the connection and state changes in your iOS client app, you have to implement all of our application delegate methods in your **`UIApplicationDelegate`** methods in appDelegate file.

After you initialize the MeetTalk, you have to connect and implement these methods in your **UIApplicationDelegate** methods in **appDelegate** file to make sure TapTalk.io runs smoothly in your application.

{% hint style="info" %}
If you have previously implemented PowerTalk SDK in your app, simply import MeeTalk.h class to your AppDelegate, then change **TapTalk** to **MeetTalk** the application delegate method implementations
{% endhint %}

| **Application Delegate Method**                                                                          | **Description**                                                                                      |
| -------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| `application:didFinishLaunchingWithOptions`                                                              | Tells the delegate that the launch process is almost done and the app is almost ready to run.        |
| `applicationWillResignActive:`                                                                           | Tells the delegate that the app is about to become inactive.                                         |
| `applicationDidEnterBackground:`                                                                         | Tells the delegate that the app is now in the background.                                            |
| `applicationWillEnterForeground:`                                                                        | Tells the delegate that the app is about to enter the foreground.                                    |
| `applicationDidBecomeActive:`                                                                            | Tells the delegate that the app has become active.                                                   |
| `applicationWillTerminate:`                                                                              | Tells the delegate when the app is about to terminate.                                               |
| <p><code>application:</code></p><p><code>didRegisterForRemoteNotificationsWithDeviceToken:</code></p>    | Tells the delegate that the app successfully registered with Apple Push Notification service (APNs). |
| <p><code>application:didReceiveRemoteNotification:</code></p><p><code>fetchCompletionHandler:</code></p> | Tells the app that a remote notification arrived that indicates there is data to be fetched.         |
| `handleException:`                                                                                       | Tells the delegate when application throws exception.                                                |

{% tabs %}
{% tab title="Objective-C" %}
{% code title="AppDelegate.m" %}

```objectivec
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
    //Implement TapTalk didFinishLaunchingWithOptions here    
    [[MeetTalk sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
    
    //Other code
    ...
    ...
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
  
    //Implement TapTalk applicationWillResignActive here
    [[MeetTalk sharedInstance] applicationWillResignActive:application];
  
    //Other code
    ...
    ...
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    //Implement TapTalk applicationDidEnterBackground here
    [[MeetTalk sharedInstance] applicationDidEnterBackground:application];
  
    //Other code
    ...
    ...
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
  
    //Implement TapTalk applicationWillEnterForeground here
    [[MeetTalk sharedInstance] applicationWillEnterForeground:application];
  
    //Other code
    ...
    ...
  }
  
- (void)applicationDidBecomeActive:(UIApplication *)application {
  
    //Implement TapTalk applicationDidBecomeActive here    
    [[MeetTalk sharedInstance] applicationDidBecomeActive:application];
  
    //Other code
    ...
    ...
}

- (void)applicationWillTerminate:(UIApplication *)application {
  
    //Implement TapTalk applicationWillTerminate here
    [[MeetTalk sharedInstance] applicationWillTerminate:application];
  
    //Other code
    ...
    ...
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="warning" %}
**Note:** You have to implement `application:didRegisterForRemoteNotificationsWithDeviceToken` and `application:didReceiveRemoteNotification` to handle and receive notification from TapTalk.io.
{% endhint %}

{% tabs %}
{% tab title="Objective-C" %}
{% code title="AppDelegate.m" %}

```objectivec
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  
    //Implement TapTalk application:didRegisterForRemoteNotificationsWithDeviceToken here
    [[MeetTalk sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
  
    //Other code
    ...
    ...
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
  
    //Implement TapTalk application:didReceiveRemoteNotification:fetchCompletionHandler here
    [[MeetTalk sharedInstance] application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
  
    //Other code
    ...
    ...
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

You have to add below code `NSSetUncaughtExceptionHandler(&handleExceptions);` in `application:didFinishLaunchingWithOptions:`method to register uncaught exception handler and add delegate function `handleExceptions`.

{% tabs %}
{% tab title="Objective-C" %}
{% code title="AppDelegate.m" %}

```objectivec
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  //Register Uncaught Exception Handler
  NSSetUncaughtExceptionHandler(&handleExceptions);
}

//Add delegate function to handle exceptions
void handleExceptions(NSException *exception) {
  //Implement TapTalk.io handleException method
  [[MeetTalk sharedInstance] handleException:exception];
}
```

{% endcode %}
{% endtab %}
{% endtabs %}

{% hint style="warning" %}
**Note:** Don't forget to register for exception handler inside `application:didFinishLaunchingWithOptions:` method and implement `handleExceptions` method in **appDelegate** class to make sure TapTalk.io able to handle exceptions.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.taptalk.io/meettalk-sdk-documentation/meettalk-ios/implement-application-delegate.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
