From a81e3a2de7a10f5d16d8632db97a301f10920631 Mon Sep 17 00:00:00 2001 From: Desu Sai Venkat <48179357+desusai7@users.noreply.github.com> Date: Tue, 9 May 2023 10:37:58 +0530 Subject: [PATCH 1/2] feat: handled retrieving carrier names as per different iOS versions --- Sources/Classes/Headers/Public/RSNetwork.h | 12 +++---- Sources/Classes/RSNetwork.m | 38 ++++++++++++++++++---- Sources/Classes/RSUtils.m | 9 +---- Tests/RudderUtilsTest.swift | 5 +++ 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/Sources/Classes/Headers/Public/RSNetwork.h b/Sources/Classes/Headers/Public/RSNetwork.h index 66577421..765ac2be 100644 --- a/Sources/Classes/Headers/Public/RSNetwork.h +++ b/Sources/Classes/Headers/Public/RSNetwork.h @@ -13,13 +13,13 @@ NS_ASSUME_NONNULL_BEGIN @interface RSNetwork : NSObject -- (instancetype) initWithDict:(NSDictionary*) dict; -- (NSDictionary*) dict; +- (instancetype)initWithDict:(NSDictionary *)dict; +- (NSDictionary *)dict; -@property (nonatomic, readwrite) NSString* carrier; -@property (nonatomic, readwrite) bool wifi; -@property (nonatomic, readwrite) bool isNetworkReachable; -@property (nonatomic, readwrite) bool cellular; +@property(nonatomic, strong) NSMutableArray *carrier; +@property(nonatomic, readwrite) bool wifi; +@property(nonatomic, readwrite) bool isNetworkReachable; +@property(nonatomic, readwrite) bool cellular; @end diff --git a/Sources/Classes/RSNetwork.m b/Sources/Classes/RSNetwork.m index 38344b88..807794ca 100644 --- a/Sources/Classes/RSNetwork.m +++ b/Sources/Classes/RSNetwork.m @@ -7,7 +7,8 @@ // #import "RSNetwork.h" - +#import "RSLogger.h" +#import "RSUtils.h" #if !TARGET_OS_TV && !TARGET_OS_WATCH #import #import @@ -19,12 +20,35 @@ - (instancetype)init { self = [super init]; if (self) { + _carrier = [[NSMutableArray alloc] init]; #if !TARGET_OS_TV && !TARGET_OS_WATCH - NSString *carrierName = [[[[CTTelephonyNetworkInfo alloc] init] subscriberCellularProvider]carrierName]; - if (carrierName == nil) { - carrierName = @"unavailable"; + CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init]; + if(@available(iOS 16.0, *)) { + [RSLogger logWarn:@"RSNetwork: init: cannot retrieve carrier names on iOS 16 and above as CTCarrier is deprecated"]; + } + else if (@available(iOS 12.0, *)) { + NSDictionary *serviceProviders = [networkInfo serviceSubscriberCellularProviders]; + for (NSString *rat in serviceProviders) { + CTCarrier *carrier = [serviceProviders objectForKey:rat]; + if(carrier == nil) { + continue; + } + NSString *carrierName = [carrier carrierName]; + if (carrierName && ![carrierName isEqualToString:@"--"]) { + [_carrier addObject:carrierName]; + } + } + } else { + CTCarrier *carrier = [networkInfo subscriberCellularProvider]; + NSString *carrierName = [carrier carrierName]; + if (carrierName) { + [_carrier addObject:carrierName]; + } + } + + if(_carrier.count == 0) { + [RSLogger logWarn:@"RSNetwork: init: unable to retrieve carrier name"]; } - _carrier = carrierName; #endif #if !TARGET_OS_WATCH SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, "8.8.8.8"); @@ -60,7 +84,9 @@ - (instancetype) initWithDict:(NSDictionary*) dict { NSMutableDictionary *tempDict; @synchronized (tempDict) { tempDict = [[NSMutableDictionary alloc] init]; - [tempDict setValue:_carrier forKey:@"carrier"]; + if(_carrier.count !=0) { + [tempDict setValue:[RSUtils getCSVString:_carrier] forKey:@"carrier"]; + } #if !TARGET_OS_WATCH if(_isNetworkReachable) { [tempDict setValue:[NSNumber numberWithBool:_wifi] forKey:@"wifi"]; diff --git a/Sources/Classes/RSUtils.m b/Sources/Classes/RSUtils.m index 19df5ce4..4ba5f362 100644 --- a/Sources/Classes/RSUtils.m +++ b/Sources/Classes/RSUtils.m @@ -128,14 +128,7 @@ + (NSArray*) serializeArray:(NSArray*) array { } +(NSString*) getCSVString:(NSArray*) inputStrings { - NSMutableString *CSVString = [[NSMutableString alloc] init]; - for (int index = 0; index < inputStrings.count; index++) { - [CSVString appendString:inputStrings[index]]; - if (index != inputStrings.count -1) { - [CSVString appendString:@","]; - } - } - return [CSVString copy]; + return [inputStrings componentsJoinedByString:@","]; } +(NSString*) getJSONCSVString:(NSArray*) inputStrings { diff --git a/Tests/RudderUtilsTest.swift b/Tests/RudderUtilsTest.swift index e48bf1bd..ca24d1f3 100644 --- a/Tests/RudderUtilsTest.swift +++ b/Tests/RudderUtilsTest.swift @@ -23,6 +23,11 @@ class RudderUtilsTest: XCTestCase { let bioCSV = RSUtils.getCSVString(bio) print(bioCSV) XCTAssert(bioCSV == "Desu,Mobile Engineer,RudderStack") + let carriers:[String] = ["Airtel"] + let carriersCSV = RSUtils.getCSVString(carriers) + print(carriersCSV) + XCTAssertEqual(carriersCSV, "Airtel") + } func testGetJSONCSVString() throws { From dad20140b09620d86e8bfd7f0a5937de16875752 Mon Sep 17 00:00:00 2001 From: GitHub actions Date: Tue, 9 May 2023 07:08:31 +0000 Subject: [PATCH 2/2] chore(release): 1.15.0 --- CHANGELOG.md | 7 +++++++ README.md | 10 +++++----- Sources/Classes/Headers/RSVersion.h | 2 +- package.json | 2 +- sonar-project.properties | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab2ebdd3..73f86397 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +## [1.15.0](https://github.com/rudderlabs/rudder-sdk-ios/compare/v1.14.0...v1.15.0) (2023-05-09) + + +### Features + +* handled retrieving carrier names as per different iOS versions ([a81e3a2](https://github.com/rudderlabs/rudder-sdk-ios/commit/a81e3a2de7a10f5d16d8632db97a301f10920631)) + ## [1.14.0](https://github.com/rudderlabs/rudder-sdk-ios/compare/v1.13.2...v1.14.0) (2023-04-19) diff --git a/README.md b/README.md index 2cb9678d..f1b02b10 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@

- +

@@ -39,7 +39,7 @@ The iOS SDK is available through [**CocoaPods**](https://cocoapods.org), [**Cart To install the SDK, simply add the following line to your Podfile: ```xcode -pod 'Rudder', '1.14.0' +pod 'Rudder', '1.15.0' ``` ### Carthage @@ -47,7 +47,7 @@ pod 'Rudder', '1.14.0' For Carthage support, add the following line to your `Cartfile`: ```xcode -github "rudderlabs/rudder-sdk-ios" "v1.14.0" +github "rudderlabs/rudder-sdk-ios" "v1.15.0" ``` > Remember to include the following code in all `.m` and `.h` files where you want to refer to or use the RudderStack SDK classes, as shown: @@ -71,7 +71,7 @@ You can also add the RudderStack iOS SDK via Swift Package Mangaer, via one of t * Enter the package repository (`git@github.com:rudderlabs/rudder-sdk-ios.git`) in the search bar. -* In **Dependency Rule**, select **Up to Next Major Version** and enter `1.14.0` as the value, as shown: +* In **Dependency Rule**, select **Up to Next Major Version** and enter `1.15.0` as the value, as shown: ![Setting dependency](https://user-images.githubusercontent.com/59817155/145574696-8c849749-13e0-40d5-aacb-3fccb5c8e67d.png) @@ -99,7 +99,7 @@ let package = Package( ], dependencies: [ // Dependencies declare other packages that this package depends on. - .package(url: "git@github.com:rudderlabs/rudder-sdk-ios.git", from: "1.14.0") + .package(url: "git@github.com:rudderlabs/rudder-sdk-ios.git", from: "1.15.0") ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. diff --git a/Sources/Classes/Headers/RSVersion.h b/Sources/Classes/Headers/RSVersion.h index f97e3878..4a19c6e8 100644 --- a/Sources/Classes/Headers/RSVersion.h +++ b/Sources/Classes/Headers/RSVersion.h @@ -8,6 +8,6 @@ #ifndef RSVersion_h #define RSVersion_h -NSString *const SDK_VERSION = @"1.14.0"; +NSString *const SDK_VERSION = @"1.15.0"; #endif /* RSVersion_h */ diff --git a/package.json b/package.json index 3c128dfe..c8fee58e 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,4 @@ { - "version": "1.14.0", + "version": "1.15.0", "description": "Rudder is a platform for collecting, storing and routing customer event data to dozens of tools" } diff --git a/sonar-project.properties b/sonar-project.properties index efe96c77..c1a137b3 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -6,7 +6,7 @@ sonar.qualitygate.wait=false sonar.projectKey=rudderlabs_rudder-sdk-ios sonar.organization=rudderlabs sonar.projectName=RudderStack iOS SDK -sonar.projectVersion=1.14.0 +sonar.projectVersion=1.15.0 # C/C++/Objective-C related details # sonar.cfamily.compile-commands=compile_commands.json