{"id":21778,"date":"2015-06-26T13:57:17","date_gmt":"2015-06-26T08:27:17","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=21778"},"modified":"2016-12-19T15:17:38","modified_gmt":"2016-12-19T09:47:38","slug":"detecting-phone-call-interruption-in-ios-app","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/detecting-phone-call-interruption-in-ios-app\/","title":{"rendered":"Detecting phone call interruption in iOS App"},"content":{"rendered":"<p style=\"text-align: justify;\">One of the default <a href=\"http:\/\/www.tothenew.com\/mobile-ios-application-development-services\">behaviors of iOS is that it stops<\/a> all the services &amp; functions of the app while you are on a phone call.<\/p>\n<p style=\"text-align: justify;\">While writing an audio-video iOS App, we must handle phone call&#8217;s interruption properly to resume the app.\u00a0It is possible\u00a0to detect a phone call and it&#8217;s states with the help of Core Telephony framework. Following steps will guide you to handle phone calls in your iPhones properly.<\/p>\n<p style=\"text-align: justify;\"><strong>Steps to follow :<\/strong><\/p>\n<p>Add\u00a0<strong>CoreTelephony<\/strong>\u00a0Framework.<\/p>\n<p>Import the following classes of <strong>CoreTelephony<\/strong>\u00a0into your class wherever you need to handle or detect phone call&#8217;s interruption.<\/p>\n<pre>#import &lt;CoreTelephony\/CTCallCenter.h&gt;\r\n#import &lt;CoreTelephony\/CTCall.h&gt;\r\n<\/pre>\n<p>Make an object of CTCallCenter into your handler class.<\/p>\n<pre>@property (nonatomic, strong) CTCallCenter *objCallCenter;<\/pre>\n<p>Add a notification observer for call state changed inside your handler class <strong>viewDidLoad<\/strong>\u00a0method.<\/p>\n<pre> [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(CallStateDidChange:) name:@\"CTCallStateDidChange\" object:nil];<\/pre>\n<p>Write a call event handler for the \u00a0call center in <strong>viewDidLoad<\/strong><\/p>\n<pre>self.objCallCenter = [[CTCallCenter alloc] init];\r\nself.objCallCenter.callEventHandler = ^(CTCall* call) {\r\n        \/\/ anounce that we've had a state change in our call center\r\n        NSDictionary *dict = [NSDictionary dictionaryWithObject:call.callState forKey:@\"callState\"];\r\n        [[NSNotificationCenter defaultCenter] postNotificationName:@\"CTCallStateDidChange\" object:nil userInfo:dict];\r\n    };\r\n<\/pre>\n<p>Write call state changed selector<\/p>\n<pre>- (void)CallStateDidChange:(NSNotification *)notification\r\n{\r\n    NSLog(@\"Notification : %@\", notification);\r\n    NSString *callInfo = [[notification userInfo] objectForKey:@\"callState\"];\r\n    \r\n    if([callInfo isEqualToString: CTCallStateDialing])\r\n    {\r\n        \/\/The call state, before connection is established, when the user initiates the call.\r\n        NSLog(@\"Call is dailing\");\r\n    }\r\n    if([callInfo isEqualToString: CTCallStateIncoming])\r\n    {\r\n        \/\/The call state, before connection is established, when a call is incoming but not yet answered by the user.\r\n        NSLog(@\"Call is Coming\");\r\n    }\r\n    \r\n    if([callInfo isEqualToString: CTCallStateConnected])\r\n    {\r\n        \/\/The call state when the call is fully established for all parties involved.\r\n        NSLog(@\"Call Connected\");\r\n    }\r\n    \r\n    if([callInfo isEqualToString: CTCallStateDisconnected])\r\n    {\r\n        \/\/The call state Ended.\r\n        NSLog(@\"Call Ended\");\r\n    }\r\n\r\n}<\/pre>\n<p>Perform the tasks according to the phone call&#8217;s state.<\/p>\n<p style=\"text-align: justify;\">Hope It Helps \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the default behaviors of iOS is that it stops all the services &amp; functions of the app while you are on a phone call. While writing an audio-video iOS App, we must handle phone call&#8217;s interruption properly to resume the app.\u00a0It is possible\u00a0to detect a phone call and it&#8217;s states with the help [&hellip;]<\/p>\n","protected":false},"author":117,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":41},"categories":[1400,1772,1],"tags":[1925,1926,4848,1923,1924,1922],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/21778"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/117"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=21778"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/21778\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=21778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=21778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=21778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}