Proyectos de Subversion Iphone Microlearning

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
// Copyright 2019 Google
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
 
15
#import "Crashlytics/Crashlytics/Settings/Operations/FIRCLSNetworkOperation.h"
16
 
17
#import "Crashlytics/Crashlytics/Components/FIRCLSApplication.h"
18
#import "Crashlytics/Crashlytics/DataCollection/FIRCLSDataCollectionToken.h"
19
#import "Crashlytics/Crashlytics/Helpers/FIRCLSDefines.h"
20
#import "Crashlytics/Crashlytics/Helpers/FIRCLSLogger.h"
21
#import "Crashlytics/Shared/FIRCLSConstants.h"
22
 
23
@interface FIRCLSNetworkOperation ()
24
 
25
@property(nonatomic, strong, readonly) NSString *googleAppID;
26
 
27
@end
28
 
29
@implementation FIRCLSNetworkOperation
30
 
31
- (instancetype)initWithGoogleAppID:(NSString *)googleAppID
32
                              token:(FIRCLSDataCollectionToken *)token {
33
  NSParameterAssert(googleAppID);
34
  if (!googleAppID) {
35
    return nil;
36
  }
37
 
38
  self = [super init];
39
  if (self) {
40
    _googleAppID = googleAppID;
41
    _token = token;
42
  }
43
  return self;
44
}
45
 
46
- (void)startWithToken:(FIRCLSDataCollectionToken *)token {
47
  // Settings is considered data collection, so we must only
48
  // call this with a valid token
49
  if (![token isValid]) {
50
    FIRCLSErrorLog(@"Skipping network operation with invalid data collection token");
51
    return;
52
  }
53
 
54
  [super start];
55
}
56
 
57
- (NSMutableURLRequest *)mutableRequestWithDefaultHTTPHeaderFieldsAndTimeoutForURL:(NSURL *)url {
58
  return [self mutableRequestWithDefaultHTTPHeadersForURL:url timeout:10.0];
59
}
60
 
61
- (NSMutableURLRequest *)mutableRequestWithDefaultHTTPHeadersForURL:(NSURL *)url
62
                                                            timeout:(NSTimeInterval)timeout {
63
  NSMutableURLRequest *request =
64
      [NSMutableURLRequest requestWithURL:url
65
                              cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
66
                          timeoutInterval:timeout];
67
 
68
  NSString *localeId = self.localeIdentifier;
69
 
70
  [request setValue:self.userAgentString forHTTPHeaderField:FIRCLSNetworkUserAgent];
71
  [request setValue:FIRCLSNetworkUTF8 forHTTPHeaderField:FIRCLSNetworkAcceptCharset];
72
  [request setValue:localeId forHTTPHeaderField:FIRCLSNetworkAcceptLanguage];
73
  [request setValue:localeId forHTTPHeaderField:FIRCLSNetworkContentLanguage];
74
  [request setValue:FIRCLSDeveloperToken forHTTPHeaderField:FIRCLSNetworkCrashlyticsDeveloperToken];
75
  [request setValue:FIRCLSApplicationGetSDKBundleID()
76
      forHTTPHeaderField:FIRCLSNetworkCrashlyticsAPIClientId];
77
  [request setValue:FIRCLSSDKVersion()
78
      forHTTPHeaderField:FIRCLSNetworkCrashlyticsAPIClientDisplayVersion];
79
  [request setValue:self.googleAppID forHTTPHeaderField:FIRCLSNetworkCrashlyticsGoogleAppId];
80
 
81
  return request;
82
}
83
 
84
- (NSString *)userAgentString {
85
  return
86
      [NSString stringWithFormat:@"%@/%@", FIRCLSApplicationGetSDKBundleID(), FIRCLSSDKVersion()];
87
}
88
 
89
- (NSString *)localeIdentifier {
90
  return NSLocale.currentLocale.localeIdentifier;
91
}
92
 
93
@end