Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Side by Side Diff: talk/examples/objc/AppRTCDemo/common/ARDUtilities.m

Issue 1235563006: Move talk/examples/* to webrtc/examples. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: 201508051337 Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * libjingle
3 * Copyright 2014 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #import "ARDUtilities.h"
29
30 #import "RTCLogging.h"
31
32 @implementation NSDictionary (ARDUtilites)
33
34 + (NSDictionary *)dictionaryWithJSONString:(NSString *)jsonString {
35 NSParameterAssert(jsonString.length > 0);
36 NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
37 NSError *error = nil;
38 NSDictionary *dict =
39 [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
40 if (error) {
41 RTCLogError(@"Error parsing JSON: %@", error.localizedDescription);
42 }
43 return dict;
44 }
45
46 + (NSDictionary *)dictionaryWithJSONData:(NSData *)jsonData {
47 NSError *error = nil;
48 NSDictionary *dict =
49 [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
50 if (error) {
51 RTCLogError(@"Error parsing JSON: %@", error.localizedDescription);
52 }
53 return dict;
54 }
55
56 @end
57
58 @implementation NSURLConnection (ARDUtilities)
59
60 + (void)sendAsyncRequest:(NSURLRequest *)request
61 completionHandler:(void (^)(NSURLResponse *response,
62 NSData *data,
63 NSError *error))completionHandler {
64 // Kick off an async request which will call back on main thread.
65 [NSURLConnection sendAsynchronousRequest:request
66 queue:[NSOperationQueue mainQueue]
67 completionHandler:^(NSURLResponse *response,
68 NSData *data,
69 NSError *error) {
70 if (completionHandler) {
71 completionHandler(response, data, error);
72 }
73 }];
74 }
75
76 // Posts data to the specified URL.
77 + (void)sendAsyncPostToURL:(NSURL *)url
78 withData:(NSData *)data
79 completionHandler:(void (^)(BOOL succeeded,
80 NSData *data))completionHandler {
81 NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
82 request.HTTPMethod = @"POST";
83 request.HTTPBody = data;
84 [[self class] sendAsyncRequest:request
85 completionHandler:^(NSURLResponse *response,
86 NSData *data,
87 NSError *error) {
88 if (error) {
89 RTCLogError(@"Error posting data: %@", error.localizedDescription);
90 if (completionHandler) {
91 completionHandler(NO, data);
92 }
93 return;
94 }
95 NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
96 if (httpResponse.statusCode != 200) {
97 NSString *serverResponse = data.length > 0 ?
98 [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] :
99 nil;
100 RTCLogError(@"Received bad response: %@", serverResponse);
101 if (completionHandler) {
102 completionHandler(NO, data);
103 }
104 return;
105 }
106 if (completionHandler) {
107 completionHandler(YES, data);
108 }
109 }];
110 }
111
112 @end
OLDNEW
« no previous file with comments | « talk/examples/objc/AppRTCDemo/common/ARDUtilities.h ('k') | talk/examples/objc/AppRTCDemo/ios/ARDAppDelegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698