From b13237b9dafd0ffbca64eba167d58a0dad410055 Mon Sep 17 00:00:00 2001 From: kthelgason Date: Thu, 30 Mar 2017 04:56:05 -0700 Subject: [PATCH] Fix deprecated methods in AppRTCMobile. Remove warning suppressions and update code that uses deprecated methods to the currently supported APIs. BUG=webrtc:5549 Review-Url: https://codereview.webrtc.org/2780433006 Cr-Commit-Position: refs/heads/master@{#17472} --- webrtc/examples/BUILD.gn | 32 +-------- .../objc/AppRTCMobile/ARDAppEngineClient.m | 66 ++++++++++--------- .../objc/AppRTCMobile/common/ARDUtilities.m | 16 ++--- .../AppRTCMobile/ios/ARDMainViewController.m | 18 +++-- .../ios/ARDVideoCallViewController.m | 20 ++++-- 5 files changed, 71 insertions(+), 81 deletions(-) diff --git a/webrtc/examples/BUILD.gn b/webrtc/examples/BUILD.gn index 782491d425..ebe426f00c 100644 --- a/webrtc/examples/BUILD.gn +++ b/webrtc/examples/BUILD.gn @@ -150,23 +150,6 @@ if (is_android) { } if (is_ios || (is_mac && target_cpu != "x86")) { - config("warnings_config") { - # GN orders flags on a target before flags from configs. The default config - # adds these flags so to cancel them out they need to come from a config and - # cannot be on the target directly. - if (is_ios) { - # Suppress compiler warnings about deprecated that triggered - # when moving from ios_deployment_target 7.0 to 9.0. - # See webrtc:5549 for more details. - cflags = [ "-Wno-deprecated-declarations" ] - cflags_objc = [ - # Enabled for cflags_objc in build/config/compiler/BUILD.gn. - # See webrtc:6520. - "-Wno-objc-missing-property-synthesis", - ] - } - } - config("apprtc_common_config") { include_dirs = [ "objc/AppRTCMobile/common" ] } @@ -177,10 +160,7 @@ if (is_ios || (is_mac && target_cpu != "x86")) { "objc/AppRTCMobile/common/ARDUtilities.h", "objc/AppRTCMobile/common/ARDUtilities.m", ] - configs += [ - ":warnings_config", - "//build/config/compiler:enable_arc", - ] + configs += [ "//build/config/compiler:enable_arc" ] public_configs = [ ":apprtc_common_config" ] deps = [ @@ -245,10 +225,7 @@ if (is_ios || (is_mac && target_cpu != "x86")) { "objc/AppRTCMobile/RTCSessionDescription+JSON.h", "objc/AppRTCMobile/RTCSessionDescription+JSON.m", ] - configs += [ - "//build/config/compiler:enable_arc", - ":warnings_config", - ] + configs += [ "//build/config/compiler:enable_arc" ] public_configs = [ ":apprtc_signaling_config" ] deps = [ ":apprtc_common", @@ -281,10 +258,7 @@ if (is_ios || (is_mac && target_cpu != "x86")) { "objc/AppRTCMobile/ios/UIImage+ARDUtilities.h", "objc/AppRTCMobile/ios/UIImage+ARDUtilities.m", ] - configs += [ - "//build/config/compiler:enable_arc", - ":warnings_config", - ] + configs += [ "//build/config/compiler:enable_arc" ] deps = [ ":apprtc_common", diff --git a/webrtc/examples/objc/AppRTCMobile/ARDAppEngineClient.m b/webrtc/examples/objc/AppRTCMobile/ARDAppEngineClient.m index d707b92d44..ad7a6c2bf2 100644 --- a/webrtc/examples/objc/AppRTCMobile/ARDAppEngineClient.m +++ b/webrtc/examples/objc/AppRTCMobile/ARDAppEngineClient.m @@ -57,29 +57,26 @@ static NSInteger const kARDAppEngineClientErrorBadResponse = -1; request.HTTPMethod = @"POST"; __weak ARDAppEngineClient *weakSelf = self; [NSURLConnection sendAsyncRequest:request - completionHandler:^(NSURLResponse *response, - NSData *data, - NSError *error) { - ARDAppEngineClient *strongSelf = weakSelf; - if (error) { - if (completionHandler) { - completionHandler(nil, error); - } - return; - } - ARDJoinResponse *joinResponse = - [ARDJoinResponse responseFromJSONData:data]; - if (!joinResponse) { - if (completionHandler) { - NSError *error = [[self class] badResponseError]; - completionHandler(nil, error); - } - return; - } - if (completionHandler) { - completionHandler(joinResponse, nil); - } - }]; + completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { + ARDAppEngineClient *strongSelf = weakSelf; + if (error) { + if (completionHandler) { + completionHandler(nil, error); + } + return; + } + ARDJoinResponse *joinResponse = [ARDJoinResponse responseFromJSONData:data]; + if (!joinResponse) { + if (completionHandler) { + NSError *error = [[self class] badResponseError]; + completionHandler(nil, error); + } + return; + } + if (completionHandler) { + completionHandler(joinResponse, nil); + } + }]; } - (void)sendMessage:(ARDSignalingMessage *)message @@ -138,17 +135,24 @@ static NSInteger const kARDAppEngineClientErrorBadResponse = -1; NSURL *url = [NSURL URLWithString:urlString]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; request.HTTPMethod = @"POST"; - NSURLResponse *response = nil; - NSError *error = nil; + + RTCLog(@"C->RS: BYE"); + __block NSError *error = nil; + // We want a synchronous request so that we know that we've left the room on // room server before we do any further work. - RTCLog(@"C->RS: BYE"); - [NSURLConnection sendSynchronousRequest:request - returningResponse:&response - error:&error]; + dispatch_semaphore_t sem = dispatch_semaphore_create(0); + [NSURLConnection sendAsyncRequest:request + completionHandler:^(NSURLResponse *response, NSData *data, NSError *e) { + if (e) { + error = e; + } + dispatch_semaphore_signal(sem); + }]; + + dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER); if (error) { - RTCLogError(@"Error leaving room %@ on room server: %@", - roomId, error.localizedDescription); + RTCLogError(@"Error leaving room %@ on room server: %@", roomId, error.localizedDescription); if (completionHandler) { completionHandler(error); } diff --git a/webrtc/examples/objc/AppRTCMobile/common/ARDUtilities.m b/webrtc/examples/objc/AppRTCMobile/common/ARDUtilities.m index c9d029f629..0ae44da4be 100644 --- a/webrtc/examples/objc/AppRTCMobile/common/ARDUtilities.m +++ b/webrtc/examples/objc/AppRTCMobile/common/ARDUtilities.m @@ -47,15 +47,13 @@ NSData *data, NSError *error))completionHandler { // Kick off an async request which will call back on main thread. - [NSURLConnection sendAsynchronousRequest:request - queue:[NSOperationQueue mainQueue] - completionHandler:^(NSURLResponse *response, - NSData *data, - NSError *error) { - if (completionHandler) { - completionHandler(response, data, error); - } - }]; + NSURLSession *session = [NSURLSession sharedSession]; + [[session dataTaskWithRequest:request + completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + if (completionHandler) { + completionHandler(response, data, error); + } + }] resume]; } // Posts data to the specified URL. diff --git a/webrtc/examples/objc/AppRTCMobile/ios/ARDMainViewController.m b/webrtc/examples/objc/AppRTCMobile/ios/ARDMainViewController.m index 75d454a44c..dca48b60c3 100644 --- a/webrtc/examples/objc/AppRTCMobile/ios/ARDMainViewController.m +++ b/webrtc/examples/objc/AppRTCMobile/ios/ARDMainViewController.m @@ -255,12 +255,18 @@ static NSString *const loopbackLaunchProcessArgument = @"loopback"; } - (void)showAlertWithMessage:(NSString*)message { - UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:nil - message:message - delegate:nil - cancelButtonTitle:@"OK" - otherButtonTitles:nil]; - [alertView show]; + UIAlertController *alert = + [UIAlertController alertControllerWithTitle:nil + message:message + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK" + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action){ + }]; + + [alert addAction:defaultAction]; + [self presentViewController:alert animated:YES completion:nil]; } @end diff --git a/webrtc/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m b/webrtc/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m index d1ae3f94e0..cd42514a9f 100644 --- a/webrtc/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m +++ b/webrtc/examples/objc/AppRTCMobile/ios/ARDVideoCallViewController.m @@ -35,6 +35,8 @@ } @synthesize videoCallView = _videoCallView; +@synthesize localVideoTrack = _localVideoTrack; +@synthesize remoteVideoTrack = _remoteVideoTrack; @synthesize delegate = _delegate; - (instancetype)initForRoom:(NSString *)room @@ -214,12 +216,18 @@ } - (void)showAlertWithMessage:(NSString*)message { - UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:nil - message:message - delegate:nil - cancelButtonTitle:@"OK" - otherButtonTitles:nil]; - [alertView show]; + UIAlertController *alert = + [UIAlertController alertControllerWithTitle:nil + message:message + preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"OK" + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *action){ + }]; + + [alert addAction:defaultAction]; + [self presentViewController:alert animated:YES completion:nil]; } @end