Commit ccd894b7 authored by Deployer's avatar Deployer

Added custom user-agent

parent 1cb2937a
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = 'CedarMaps' s.name = 'CedarMaps'
s.version = '3.1.2' s.version = '3.1.3'
s.summary = 'CedarMaps iOS SDK' s.summary = 'CedarMaps iOS SDK'
# This description is used to generate tags and improve search results. # This description is used to generate tags and improve search results.
......
...@@ -99,6 +99,8 @@ typedef NS_OPTIONS(NSUInteger, CSPlacemarkType) { ...@@ -99,6 +99,8 @@ typedef NS_OPTIONS(NSUInteger, CSPlacemarkType) {
CSPlacemarkTypeExpressway = 1 << 4, CSPlacemarkTypeExpressway = 1 << 4,
CSPlacemarkTypeBoulevard = 1 << 5, CSPlacemarkTypeBoulevard = 1 << 5,
CSPlacemarkTypeLocality = 1 << 6, CSPlacemarkTypeLocality = 1 << 6,
CSPlacemarkTypePOI = 1 << 7 CSPlacemarkTypePOI = 1 << 7,
CSPlacemarkTypeCity = 1 << 8,
CSPlacemarkTypeState = 1 << 9
}; };
NSString* _Nonnull stringValueForPlacemarkType(CSPlacemarkType type); NSString* _Nonnull stringValueForPlacemarkType(CSPlacemarkType type);
...@@ -70,6 +70,12 @@ NSString* stringValueForPlacemarkType(CSPlacemarkType type) { ...@@ -70,6 +70,12 @@ NSString* stringValueForPlacemarkType(CSPlacemarkType type) {
if (type & CSPlacemarkTypePOI) { if (type & CSPlacemarkTypePOI) {
result = [result stringByAppendingString:@"poi,"]; result = [result stringByAppendingString:@"poi,"];
} }
if (type & CSPlacemarkTypeCity) {
result = [result stringByAppendingString:@"city,"];
}
if (type & CSPlacemarkTypeState) {
result = [result stringByAppendingString:@"state,"];
}
if (result.length > 1) { if (result.length > 1) {
result = [result substringToIndex:result.length - 1]; result = [result substringToIndex:result.length - 1];
} }
......
...@@ -5,12 +5,15 @@ ...@@ -5,12 +5,15 @@
#import "CSReverseGeocodeResponse.h" #import "CSReverseGeocodeResponse.h"
#import "CSForwardGeocodeResponse.h" #import "CSForwardGeocodeResponse.h"
#import "CSDirectionResponse.h" #import "CSDirectionResponse.h"
#import <sys/utsname.h>
#import <TargetConditionals.h>
typedef void (^CSNetworkResponseCompletionHandler)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error); typedef void (^CSNetworkResponseCompletionHandler)(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error);
@interface CSMapKit () @interface CSMapKit ()
@property (nonatomic, strong, nonnull) NSString *directionProfile; @property (nonatomic, strong, nonnull) NSString *directionProfile;
@property (nonatomic, strong, nonnull) NSString *userAgent;
@end @end
...@@ -32,12 +35,84 @@ typedef void (^CSNetworkResponseCompletionHandler)(NSData * _Nullable data, NSUR ...@@ -32,12 +35,84 @@ typedef void (^CSNetworkResponseCompletionHandler)(NSData * _Nullable data, NSUR
static id _sharedSession = nil; static id _sharedSession = nil;
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
_sharedSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:nil delegateQueue:[NSOperationQueue mainQueue]]; NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
configuration.HTTPAdditionalHeaders = @{@"User-Agent": [[CSMapKit sharedMapKit] userAgent]};
_sharedSession = [NSURLSession sessionWithConfiguration:configuration delegate:nil delegateQueue:[NSOperationQueue mainQueue]];
}); });
return _sharedSession; return _sharedSession;
} }
- (NSString *)userAgent {
if (!_userAgent) {
NSMutableArray<NSString *> *components = [[NSMutableArray alloc] init];
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
if (!appName) {
appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
}
if (appName) {
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
if (!version) {
version = @"";
}
NSString *build = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
if (!build) {
build = @"";
}
[components addObject:[NSString stringWithFormat:@"%@/%@(%@)", appName, version, build]];
}
NSString *locale = [[NSLocale preferredLanguages] firstObject];
if (locale) {
[components addObject:locale];
}
NSString *system;
#if TARGET_OS_SIMULATOR
system = @"Simulator";
#elif TARGET_OS_IOS
system = @"iOS";
#elif TARGET_OS_WATCH
system = @"watchOS";
#elif TARGET_OS_TV
system = @"tvOS";
#elif TARGET_OS_UNIX
system = @"Unix";
#elif TARGET_OS_MAC
system = @"macOS"
#else
system = @"Unknown";
#endif
NSOperatingSystemVersion systemVersion = [[[NSProcessInfo alloc] init] operatingSystemVersion];
[components addObject:[NSString stringWithFormat:@"%@/%li.%li.%li", system, (long)systemVersion.majorVersion, (long)systemVersion.minorVersion, (long)systemVersion.patchVersion]];
struct utsname systemInfo;
uname(&systemInfo);
NSString *identifier = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
[components addObject:identifier];
NSString *chip;
#if TARGET_CPU_X86_64
chip = @"x86_64";
#elif TARGET_CPU_X86
chip = @"i386";
#elif TARGET_CPU_ARM
chip = @"arm";
#elif TARGET_CPU_ARM64
chip = @"arm64";
#else
chip = @"Unknown";
#endif
[components addObject:[NSString stringWithFormat:@"(%@)", chip]];
_userAgent = [components componentsJoinedByString:@" "];
}
return _userAgent;
}
- (void)setCredentialsWithClientID:(NSString *)clientID clientSecret:(NSString *)clientSecret { - (void)setCredentialsWithClientID:(NSString *)clientID clientSecret:(NSString *)clientSecret {
[[CSAuthenticationManager sharedAuthenticationManager] setCredentialsWithClientID:clientID clientSecret:clientSecret]; [[CSAuthenticationManager sharedAuthenticationManager] setCredentialsWithClientID:clientID clientSecret:clientSecret];
} }
...@@ -167,14 +242,14 @@ typedef void (^CSNetworkResponseCompletionHandler)(NSData * _Nullable data, NSUR ...@@ -167,14 +242,14 @@ typedef void (^CSNetworkResponseCompletionHandler)(NSData * _Nullable data, NSUR
- (void)geocodeAddressString:(NSString *)addressString - (void)geocodeAddressString:(NSString *)addressString
completionHandler:(CSForwardGeocodeCompletionHandler)completionHandler { completionHandler:(CSForwardGeocodeCompletionHandler)completionHandler {
[self geocodeAddressString:addressString withType:CSPlacemarkTypeAll limit:30 completionHandler:completionHandler]; [self geocodeAddressString:addressString withType:CSPlacemarkTypeAll limit:30 customParameters:nil completionHandler:completionHandler];
} }
- (void)geocodeAddressString:(NSString *)addressString - (void)geocodeAddressString:(NSString *)addressString
withType:(CSPlacemarkType)type withType:(CSPlacemarkType)type
limit:(NSInteger)limit limit:(NSInteger)limit
completionHandler:(CSForwardGeocodeCompletionHandler)completionHandler { completionHandler:(CSForwardGeocodeCompletionHandler)completionHandler {
[self geocodeAddressString:addressString withType:type limit:limit completionHandler:completionHandler]; [self geocodeAddressString:addressString withType:type limit:limit customParameters:nil completionHandler:completionHandler];
} }
- (void)geocodeAddressString:(NSString *)addressString - (void)geocodeAddressString:(NSString *)addressString
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
301197921FA9C9190048E53D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 301197941FA9C9190048E53D /* Main.storyboard */; }; 301197921FA9C9190048E53D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 301197941FA9C9190048E53D /* Main.storyboard */; };
301197991FA9CB640048E53D /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3011979B1FA9CB640048E53D /* Localizable.strings */; }; 301197991FA9CB640048E53D /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 3011979B1FA9CB640048E53D /* Localizable.strings */; };
30616DF621D8D7EB00A1551C /* Pods_CedarMaps_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 30616DF521D8D7EB00A1551C /* Pods_CedarMaps_Example.framework */; };
3099D1931F9F31E400CB85F2 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3099D1921F9F31E400CB85F2 /* Launch Screen.storyboard */; }; 3099D1931F9F31E400CB85F2 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 3099D1921F9F31E400CB85F2 /* Launch Screen.storyboard */; };
30CBE8E41FA666D6002D6F0F /* CSReverseGeocodeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30CBE8E31FA666D6002D6F0F /* CSReverseGeocodeViewController.swift */; }; 30CBE8E41FA666D6002D6F0F /* CSReverseGeocodeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30CBE8E31FA666D6002D6F0F /* CSReverseGeocodeViewController.swift */; };
30CBE8E61FA67BEE002D6F0F /* CSMapSnapshotViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30CBE8E51FA67BEE002D6F0F /* CSMapSnapshotViewController.swift */; }; 30CBE8E61FA67BEE002D6F0F /* CSMapSnapshotViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30CBE8E51FA67BEE002D6F0F /* CSMapSnapshotViewController.swift */; };
...@@ -24,7 +25,6 @@ ...@@ -24,7 +25,6 @@
6003F59E195388D20070C39A /* CSAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F59D195388D20070C39A /* CSAppDelegate.m */; }; 6003F59E195388D20070C39A /* CSAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F59D195388D20070C39A /* CSAppDelegate.m */; };
6003F5A7195388D20070C39A /* CSMapViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5A6195388D20070C39A /* CSMapViewController.m */; }; 6003F5A7195388D20070C39A /* CSMapViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6003F5A6195388D20070C39A /* CSMapViewController.m */; };
6003F5A9195388D20070C39A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5A8195388D20070C39A /* Images.xcassets */; }; 6003F5A9195388D20070C39A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5A8195388D20070C39A /* Images.xcassets */; };
B267679F63D83A3226F6C73B /* Pods_CedarMaps_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77747B60BCD1A8149C40ED6B /* Pods_CedarMaps_Example.framework */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
3011979A1FA9CB640048E53D /* fa */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fa; path = fa.lproj/Localizable.strings; sourceTree = "<group>"; }; 3011979A1FA9CB640048E53D /* fa */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fa; path = fa.lproj/Localizable.strings; sourceTree = "<group>"; };
3011979C1FA9CB6C0048E53D /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; }; 3011979C1FA9CB6C0048E53D /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/Localizable.strings; sourceTree = "<group>"; };
3060EFAC1FA9DAF900F1841E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Main.strings; sourceTree = "<group>"; }; 3060EFAC1FA9DAF900F1841E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Main.strings; sourceTree = "<group>"; };
30616DF521D8D7EB00A1551C /* Pods_CedarMaps_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_CedarMaps_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3099D1921F9F31E400CB85F2 /* Launch Screen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; }; 3099D1921F9F31E400CB85F2 /* Launch Screen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; };
30CBE8E21FA666D6002D6F0F /* CedarMaps_Example-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CedarMaps_Example-Bridging-Header.h"; sourceTree = "<group>"; }; 30CBE8E21FA666D6002D6F0F /* CedarMaps_Example-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CedarMaps_Example-Bridging-Header.h"; sourceTree = "<group>"; };
30CBE8E31FA666D6002D6F0F /* CSReverseGeocodeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSReverseGeocodeViewController.swift; sourceTree = "<group>"; }; 30CBE8E31FA666D6002D6F0F /* CSReverseGeocodeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CSReverseGeocodeViewController.swift; sourceTree = "<group>"; };
...@@ -78,7 +79,7 @@ ...@@ -78,7 +79,7 @@
6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */, 6003F590195388D20070C39A /* CoreGraphics.framework in Frameworks */,
6003F592195388D20070C39A /* UIKit.framework in Frameworks */, 6003F592195388D20070C39A /* UIKit.framework in Frameworks */,
6003F58E195388D20070C39A /* Foundation.framework in Frameworks */, 6003F58E195388D20070C39A /* Foundation.framework in Frameworks */,
B267679F63D83A3226F6C73B /* Pods_CedarMaps_Example.framework in Frameworks */, 30616DF621D8D7EB00A1551C /* Pods_CedarMaps_Example.framework in Frameworks */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
...@@ -108,6 +109,7 @@ ...@@ -108,6 +109,7 @@
6003F58C195388D20070C39A /* Frameworks */ = { 6003F58C195388D20070C39A /* Frameworks */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
30616DF521D8D7EB00A1551C /* Pods_CedarMaps_Example.framework */,
6003F58D195388D20070C39A /* Foundation.framework */, 6003F58D195388D20070C39A /* Foundation.framework */,
6003F58F195388D20070C39A /* CoreGraphics.framework */, 6003F58F195388D20070C39A /* CoreGraphics.framework */,
6003F591195388D20070C39A /* UIKit.framework */, 6003F591195388D20070C39A /* UIKit.framework */,
......
...@@ -74,11 +74,11 @@ ...@@ -74,11 +74,11 @@
</BuildableProductRunnable> </BuildableProductRunnable>
<CommandLineArguments> <CommandLineArguments>
<CommandLineArgument <CommandLineArgument
argument = "-AppleLanguages &quot;(fa)&quot;" argument = "-AppleLocale &quot;fa-IR&quot;"
isEnabled = "YES"> isEnabled = "YES">
</CommandLineArgument> </CommandLineArgument>
<CommandLineArgument <CommandLineArgument
argument = "-AppleLocale &quot;fa_IR&quot;" argument = "-AppleLanguages &quot;(fa)&quot;"
isEnabled = "YES"> isEnabled = "YES">
</CommandLineArgument> </CommandLineArgument>
</CommandLineArguments> </CommandLineArguments>
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ {
[[CSMapKit sharedMapKit] setCredentialsWithClientID:@"YOUR_CLIENT_ID" [[CSMapKit sharedMapKit] setCredentialsWithClientID:@"CLIENT_ID"
clientSecret:@"YOUR_CLIENT_SECRET"]; clientSecret:@"CLIENT_STREET"];
[[CSMapKit sharedMapKit] setMapID:@"cedarmaps.mix"]; [[CSMapKit sharedMapKit] setMapID:@"cedarmaps.mix"];
[[CSMapKit sharedMapKit] prepareMapTiles:^(BOOL isReady, NSError * _Nullable error) { [[CSMapKit sharedMapKit] prepareMapTiles:^(BOOL isReady, NSError * _Nullable error) {
......
...@@ -85,7 +85,9 @@ extension CSForwardGeocodePlacemark { ...@@ -85,7 +85,9 @@ extension CSForwardGeocodePlacemark {
"street": "خیابان", "street": "خیابان",
"locality": "محله", "locality": "محله",
"poi": "مکان", "poi": "مکان",
"region": "منطقه" "region": "منطقه",
"city": "شهر",
"state": "استان"
] ]
return streetType[type] ?? "نامشخص" return streetType[type] ?? "نامشخص"
} }
......
...@@ -5,7 +5,7 @@ PODS: ...@@ -5,7 +5,7 @@ PODS:
- Mantle (2.1.0): - Mantle (2.1.0):
- Mantle/extobjc (= 2.1.0) - Mantle/extobjc (= 2.1.0)
- Mantle/extobjc (2.1.0) - Mantle/extobjc (2.1.0)
- Mapbox-iOS-SDK (4.4.1) - Mapbox-iOS-SDK (4.7.1)
DEPENDENCIES: DEPENDENCIES:
- CedarMaps (from `../`) - CedarMaps (from `../`)
...@@ -22,7 +22,7 @@ EXTERNAL SOURCES: ...@@ -22,7 +22,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS: SPEC CHECKSUMS:
CedarMaps: bcdfbaba6cbb00420e636ee40bab7849442c7693 CedarMaps: bcdfbaba6cbb00420e636ee40bab7849442c7693
Mantle: 2fa750afa478cd625a94230fbf1c13462f29395b Mantle: 2fa750afa478cd625a94230fbf1c13462f29395b
Mapbox-iOS-SDK: e6a4f236c77f914ca2e19b929c6cc6b077ba1c4c Mapbox-iOS-SDK: f9292a75e8cd5eb828f4432623bfc48aac42146a
PODFILE CHECKSUM: ad43b9956cf1f58bff64834a5e21f42f322108fa PODFILE CHECKSUM: ad43b9956cf1f58bff64834a5e21f42f322108fa
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment