You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2017/11/09 13:43:28 UTC
[GitHub] SpencerEJameson closed pull request #348: CB-13535: (ios) Add CallStart/CallEnd events to fire with Resign/Active events
SpencerEJameson closed pull request #348: CB-13535: (ios) Add CallStart/CallEnd events to fire with Resign/Active events
URL: https://github.com/apache/cordova-ios/pull/348
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/CordovaLib/Classes/Public/CDVViewController.m b/CordovaLib/Classes/Public/CDVViewController.m
index d0c05865a..b06fa1767 100644
--- a/CordovaLib/Classes/Public/CDVViewController.m
+++ b/CordovaLib/Classes/Public/CDVViewController.m
@@ -28,6 +28,10 @@ Licensed to the Apache Software Foundation (ASF) under one
#import "CDVLocalStorage.h"
#import "CDVCommandDelegateImpl.h"
#import <Foundation/NSCharacterSet.h>
+#import <CoreTelephony/CTCallCenter.h>
+#import <CoreTelephony/CTCall.h>
+#import <CallKit/CXCallObserver.h>
+#import <CallKit/CXCall.h>
@interface CDVViewController () {
NSInteger _userAgentLockToken;
@@ -39,6 +43,7 @@ @interface CDVViewController () {
@property (nonatomic, readwrite, strong) NSMutableArray* startupPluginNames;
@property (nonatomic, readwrite, strong) NSDictionary* pluginsMap;
@property (nonatomic, readwrite, strong) id <CDVWebViewEngineProtocol> webViewEngine;
+@property (nonatomic, readwrite, strong) CXCallObserver* callObserver;
@property (readwrite, assign) BOOL initialized;
@@ -74,6 +79,11 @@ - (void)__init
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification object:nil];
+ if (IsAtLeastiOSVersion(@"10.0")) {
+ CXCallObserver *callObserver = [[CXCallObserver alloc] init];
+ [callObserver setDelegate:self queue:nil];
+ self.callObserver = callObserver;
+ }
// read from UISupportedInterfaceOrientations (or UISupportedInterfaceOrientations~iPad, if its iPad) from -Info.plist
self.supportedOrientations = [self parseInterfaceOrientations:
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"UISupportedInterfaceOrientations"]];
@@ -343,9 +353,9 @@ - (void)viewDidLoad
}
}
}];
-
+
// /////////////////
-
+
NSString* bgColorString = [self.settings cordovaSettingForKey:@"BackgroundColor"];
UIColor* bgColor = [self colorFromColorString:bgColorString];
[self.webView setBackgroundColor:bgColor];
@@ -405,16 +415,16 @@ - (UIColor*)colorFromColorString:(NSString*)colorString
if (!colorString) {
return nil;
}
-
+
// Validate format
NSError* error = NULL;
NSRegularExpression* regex = [NSRegularExpression regularExpressionWithPattern:@"^(#[0-9A-F]{3}|(0x|#)([0-9A-F]{2})?[0-9A-F]{6})$" options:NSRegularExpressionCaseInsensitive error:&error];
NSUInteger countMatches = [regex numberOfMatchesInString:colorString options:0 range:NSMakeRange(0, [colorString length])];
-
+
if (!countMatches) {
return nil;
}
-
+
// #FAB to #FFAABB
if ([colorString hasPrefix:@"#"] && [colorString length] == 4) {
NSString* r = [colorString substringWithRange:NSMakeRange(1, 1)];
@@ -422,22 +432,22 @@ - (UIColor*)colorFromColorString:(NSString*)colorString
NSString* b = [colorString substringWithRange:NSMakeRange(3, 1)];
colorString = [NSString stringWithFormat:@"#%@%@%@%@%@%@", r, r, g, g, b, b];
}
-
+
// #RRGGBB to 0xRRGGBB
colorString = [colorString stringByReplacingOccurrencesOfString:@"#" withString:@"0x"];
-
+
// 0xRRGGBB to 0xAARRGGBB
if ([colorString hasPrefix:@"0x"] && [colorString length] == 8) {
colorString = [@"0xFF" stringByAppendingString:[colorString substringFromIndex:2]];
}
-
+
// 0xAARRGGBB to int
unsigned colorValue = 0;
NSScanner *scanner = [NSScanner scannerWithString:colorString];
if (![scanner scanHexInt:&colorValue]) {
return nil;
}
-
+
// int to UIColor
return [UIColor colorWithRed:((float)((colorValue & 0x00FF0000) >> 16))/255.0
green:((float)((colorValue & 0x0000FF00) >> 8))/255.0
@@ -480,9 +490,9 @@ - (BOOL)shouldAutorotate
}
// CB-12098
-#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
-- (NSUInteger)supportedInterfaceOrientations
-#else
+#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
+- (NSUInteger)supportedInterfaceOrientations
+#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif
{
@@ -728,6 +738,16 @@ - (void)onAppWillResignActive:(NSNotification*)notification
{
// NSLog(@"%@",@"applicationWillResignActive");
[self.commandDelegate evalJs:@"cordova.fireDocumentEvent('resign');" scheduledOnRunLoop:NO];
+
+ if (!IsAtLeastiOSVersion(@"10.0")) {
+ CTCallCenter *callCenter = [[CTCallCenter alloc] init];
+ for (CTCall *call in callCenter.currentCalls) {
+ if (call.callState == CTCallStateConnected) {
+ [self.commandDelegate evalJs:@"cordova.fireDocumentEvent('callstart');"];
+ break;
+ }
+ }
+ }
}
/*
@@ -753,6 +773,27 @@ - (void)onAppDidBecomeActive:(NSNotification*)notification
{
// NSLog(@"%@",@"applicationDidBecomeActive");
[self.commandDelegate evalJs:@"cordova.fireDocumentEvent('active');"];
+
+ if (!IsAtLeastiOSVersion(@"10.0")) {
+ CTCallCenter *callCenter = [[CTCallCenter alloc] init];
+ for (CTCall *call in callCenter.currentCalls) {
+ if (call.callState == CTCallStateDisconnected) {
+ [self.commandDelegate evalJs:@"cordova.fireDocumentEvent('callend');"];
+ break;
+ }
+ }
+ }
+}
+
+// Used for iOS 10.0+
+- (void)callObserver:(CXCallObserver *)callObserver callChanged:(CXCall *)call {
+ if (call.hasEnded) {
+ [self.commandDelegate evalJs:@"cordova.fireDocumentEvent('callend');"];
+ }
+
+ if (call.hasConnected) {
+ [self.commandDelegate evalJs:@"cordova.fireDocumentEvent('callstart');"];
+ }
}
/*
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org