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 TapTalk.io, 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.
TapTalk Application Delegate Metho
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.
application:
didRegisterForRemoteNotificationsWithDeviceToken:
Tells the delegate that the app successfully registered with Apple Push Notification service (APNs).
application:didReceiveRemoteNotification:
fetchCompletionHandler:
Tells the app that a remote notification arrived that indicates there is data to be fetched.
handleException:
Tells the delegate when application throws exception.
Objective-C
AppDelegate.m
1
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
2
3
//Implement TapTalk didFinishLaunchingWithOptions here
4
[[TapTalk sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
5
6
//Other code
7
...
8
...
9
10
return YES;
11
}
12
13
- (void)applicationWillResignActive:(UIApplication *)application {
14
15
//Implement TapTalk applicationWillResignActive here
16
[[TapTalk sharedInstance] applicationWillResignActive:application];
17
18
//Other code
19
...
20
...
21
}
22
23
- (void)applicationDidEnterBackground:(UIApplication *)application {
24
//Implement TapTalk applicationDidEnterBackground here
25
[[TapTalk sharedInstance] applicationDidEnterBackground:application];
26
27
//Other code
28
...
29
...
30
}
31
32
- (void)applicationWillEnterForeground:(UIApplication *)application {
33
34
//Implement TapTalk applicationWillEnterForeground here
35
[[TapTalk sharedInstance] applicationWillEnterForeground:application];
36
37
//Other code
38
...
39
...
40
}
41
42
- (void)applicationDidBecomeActive:(UIApplication *)application {
43
44
//Implement TapTalk applicationDidBecomeActive here
45
[[TapTalk sharedInstance] applicationDidBecomeActive:application];
46
47
//Other code
48
...
49
...
50
}
51
52
- (void)applicationWillTerminate:(UIApplication *)application {
53
54
//Implement TapTalk applicationWillTerminate here
55
[[TapTalk sharedInstance] applicationWillTerminate:application];
56
57
//Other code
58
...
59
...
60
}
Copied!
Note: You have to implement application:didRegisterForRemoteNotificationsWithDeviceToken and application:didReceiveRemoteNotification to handle and receive notification from TapTalk.io.
Objective-C
AppDelegate.m
1
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
2
3
//Implement TapTalk application:didRegisterForRemoteNotificationsWithDeviceToken here
4
[[TapTalk sharedInstance] application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
5
6
//Other code
7
...
8
...
9
}
10
11
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))completionHandler {
12
13
//Implement TapTalk application:didReceiveRemoteNotification:fetchCompletionHandler here
14
[[TapTalk sharedInstance] application:application didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
15
16
//Other code
17
...
18
...
19
}
Copied!
You have to add below code NSSetUncaughtExceptionHandler(&handleExceptions); in application:didFinishLaunchingWithOptions:method to register uncaught exception handler and add delegate function handleExceptions.
Objective-C
AppDelegate.m
1
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
2
3
//Register Uncaught Exception Handler
4
NSSetUncaughtExceptionHandler(&handleExceptions);
5
}
6
7
//Add delegate function to handle exceptions
8
void handleExceptions(NSException *exception) {
9
//Implement TapTalk.io handleException method
10
[[TapTalk sharedInstance] handleException:exception];
11
}
Copied!
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.
Last modified 1yr ago
Copy link