-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxolawareUIResponderWithCoreTelelphonyHandling.m
More file actions
67 lines (52 loc) · 1.72 KB
/
xolawareUIResponderWithCoreTelelphonyHandling.m
File metadata and controls
67 lines (52 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//
// xolawareUIResponderWithCoreTelelphonyHandling.m
// voyeur
//
// Created by me on 2012.06.27.
#include "xolawareOpenSourceCopyright.h" // Copyright (c) 2012 xolaware.
#import "xolawareUIResponderWithCoreTelelphonyHandling.h"
#import <CoreTelephony/CTCall.h>
#import <CoreTelephony/CTCallCenter.h>
NSString* const xolawareCoreTelephonyCall = @"xolawareCoreTelephonyCall";
NSString* const xolawareCoreTelephonyCallDidChangeNotification = @"xolawareCTCallStateDidChangeNotification";
@interface xolawareUIResponderWithCoreTelelphonyHandling ()
@property (strong, nonatomic) CTCallCenter* callCenter;
@end
@implementation xolawareUIResponderWithCoreTelelphonyHandling
@synthesize callCenter = _callCenter;
- (CTCallCenter*)callCenter {
if (!_callCenter)
{
_callCenter = [[CTCallCenter alloc] init];
#if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_4_3
__weak xolawareUIResponderWithCoreTelelphonyHandling* blockCoreTelphonyHandlingObject = self;
#else
__block UIResponderWithCoreTelelphonyHandling* blockCoreTelphonyHandlingObject = self;
#endif
_callCenter.callEventHandler = ^(CTCall* call) {
NSDictionary* userInfo
= [NSDictionary dictionaryWithObject:call forKey:xolawareCoreTelephonyCall];
NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
[defaultCenter postNotificationName:xolawareCoreTelephonyCallDidChangeNotification
object:blockCoreTelphonyHandlingObject
userInfo:userInfo];
};
}
return _callCenter;
}
- (BOOL)isInCall {
return nil != self.callCenter.currentCalls;
}
#if __has_feature(objc_arc)
- (void)dealloc
{
_callCenter.callEventHandler = nil;
_callCenter = nil;
}
#else
- (void)dealloc {
[_callCenter dealloc];
[super dealloc];
}
#endif
@end