I want to get the state of phone call either it in dialed, connected or disconnected...
I tried my self but i cant get the state.
NSString *phoneNumb
You should check the CTCall's callState property in order to catch it
Use a cellular call’s CTCall object to obtain an identifier for the call and to determine the call’s state.
extern NSString const *CTCallStateDialing;
extern NSString const *CTCallStateIncoming;
extern NSString const *CTCallStateConnected;
extern NSString const *CTCallStateDisconnected;
are string constants. You for loop doesn't make sense.
NSString *phoneNumber = [@"telprompt://" stringByAppendingString:@"9723539389"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
self.callCenter = [[CTCallCenter alloc] init];
[callCenter setCallEventHandler:^(CTCall* call)
{
if ([call.callState isEqualToString: CTCallStateConnected])
{
NSLog(@"Connected");
}
else if ([call.callState isEqualToString: CTCallStateDialing])
{
NSLog(@"Dialing");
}
else if ([call.callState isEqualToString: CTCallStateDisconnected])
{
NSLog(@"Disconnected");
} else if ([call.callState isEqualToString: CTCallStateIncoming])
{
NSLog(@"Incoming");
}
}];
NOTE:
@property(nonatomic, strong) CTCallCenter *callCenter;
should be declared in Appdelegate and retain it. Otherwise it will be considered as local variable & deallocated as soon as come out of loop
UPDATES:
TO ANSWER "callCenter is declared in appdelegate, how can i use it with self? and other thing when [] added to that block then it shows error on equal to "expected ']' ""
replace self.callCenter with these lines
YourApplicationDelegateClass *appDel =(YourApplicationDelegateClass*)[UIApplication sharedApplication].delegate;
appDel.callCenter = [[CTCallCenter alloc] init];