Skip to content

Commit

Permalink
fix custom logger test and example apps/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
umair-ably committed Aug 5, 2024
1 parent 699bfdf commit 421758c
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 36 deletions.
28 changes: 14 additions & 14 deletions Examples/AblyPush/AblyPushExample/AblyHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ class AblyHelper: NSObject, ObservableObject {

private var locationManager: CLLocationManager!

private(set) var realtime: ARTRealtime!
private(set) var realtime: Realtime!

private let key = "" // Your API Key from your app's dashboard

var defaultDeviceToken: String?

var locationDeviceToken: String?

var activatePushCallback: ((String?, String?, ARTErrorInfo?) -> ())?
var activatePushCallback: ((String?, String?, ErrorInfo?) -> ())?

@Published var isSubscribedToExampleChannel1 = false
@Published var isSubscribedToExampleChannel2 = false
Expand All @@ -27,10 +27,10 @@ class AblyHelper: NSObject, ObservableObject {
guard key != "" else {
preconditionFailure("Obtain your API key at https://ably.com/accounts/")
}
let options = ARTClientOptions(key: key)
let options = ClientOptions(key: key)
options.clientId = "basic-apns-example"
options.pushRegistererDelegate = self
self.realtime = ARTRealtime(options: options)
self.realtime = Realtime(options: options)
UNUserNotificationCenter.current().delegate = self
locationManager = CLLocationManager()
locationManager.delegate = self
Expand All @@ -40,7 +40,7 @@ class AblyHelper: NSObject, ObservableObject {

extension AblyHelper {

func activatePush(_ callback: @escaping (String?, String?, ARTErrorInfo?) -> ()) {
func activatePush(_ callback: @escaping (String?, String?, ErrorInfo?) -> ()) {
Self.requestUserNotificationAuthorization()
realtime.push.activate()
activatePushCallback = callback
Expand All @@ -49,10 +49,10 @@ extension AblyHelper {
func activateLocationPush() {
locationManager.startMonitoringLocationPushes { deviceToken, error in
guard error == nil else {
return ARTPush.didFailToRegisterForLocationNotificationsWithError(error!, realtime: self.realtime)
return Push.didFailToRegisterForLocationNotificationsWithError(error!, realtime: self.realtime)
}
self.locationDeviceToken = deviceToken!.deviceTokenString
ARTPush.didRegisterForLocationNotifications(withDeviceToken: deviceToken!, realtime: self.realtime)
Push.didRegisterForLocationNotifications(withDeviceToken: deviceToken!, realtime: self.realtime)
}
}

Expand All @@ -68,7 +68,7 @@ extension AblyHelper {
}
}

func getDeviceDetails(_ callback: @escaping (ARTDeviceDetails?, ARTErrorInfo?) -> ()) {
func getDeviceDetails(_ callback: @escaping (DeviceDetails?, ErrorInfo?) -> ()) {
realtime.push.admin.deviceRegistrations.get(realtime.device.id, callback: callback)
}

Expand All @@ -93,7 +93,7 @@ extension AblyHelper {
}

func sendPushToChannel(_ channel: Channel) {
let message = ARTMessage(name: "example", data: "rest data")
let message = Message(name: "example", data: "rest data")
message.extras = [
"push": [
"notification": [
Expand All @@ -105,7 +105,7 @@ extension AblyHelper {
"baz": "qux"
]
]
] as any ARTJsonCompatible
] as any JsonCompatible

realtime.channels.get(channel.rawValue).publish([message]) { error in
if let error {
Expand Down Expand Up @@ -151,9 +151,9 @@ extension AblyHelper {
}
}

extension AblyHelper: ARTPushRegistererDelegate {
extension AblyHelper: PushRegistererDelegate {

func didActivateAblyPush(_ error: ARTErrorInfo?) {
func didActivateAblyPush(_ error: ErrorInfo?) {
print("Push activation: \(error?.localizedDescription ?? "Success")")
activatePushCallback?(defaultDeviceToken, locationDeviceToken, error)
activateLocationPush()
Expand All @@ -162,14 +162,14 @@ extension AblyHelper: ARTPushRegistererDelegate {
}
}

func didDeactivateAblyPush(_ error: ARTErrorInfo?) {
func didDeactivateAblyPush(_ error: ErrorInfo?) {
print("Push deactivation: \(error?.localizedDescription ?? "Success")")
if error == nil {
isPushActivated = false
}
}

func didUpdateAblyPush(_ error: ARTErrorInfo?) {
func didUpdateAblyPush(_ error: ErrorInfo?) {
print("Push update: \(error?.localizedDescription ?? "Success")")
activatePushCallback?(defaultDeviceToken, locationDeviceToken, error)
}
Expand Down
6 changes: 3 additions & 3 deletions Examples/AblyPush/AblyPushExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ struct ContentView: View {
@StateObject private var ablyHelper = AblyHelper.shared

@State var showDeviceDetailsAlert = false
@State var deviceDetails: ARTDeviceDetails?
@State var deviceDetailsError: ARTErrorInfo?
@State var deviceDetails: DeviceDetails?
@State var deviceDetailsError: ErrorInfo?

@State var showDeviceTokensAlert = false
@State var defaultDeviceToken: String?
@State var locationDeviceToken: String?
@State var deviceTokensError: ARTErrorInfo?
@State var deviceTokensError: ErrorInfo?

var body: some View {
NavigationView {
Expand Down
6 changes: 3 additions & 3 deletions Examples/SPM/Tests/SPMTests/SPMTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

final class SPMTests: XCTestCase {
func ablyInitTest() {
let clientOptions = ARTClientOptions()
let _ = ARTRest(options: clientOptions)
let _ = ARTRealtime(options: clientOptions)
let clientOptions = ClientOptions()
let _ = Rest(options: clientOptions)
let _ = Realtime(options: clientOptions)
}
}
2 changes: 2 additions & 0 deletions Examples/Tests/Tests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = io.ably.Tests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -496,6 +497,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = Tests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = io.ably.Tests;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
14 changes: 7 additions & 7 deletions Examples/Tests/TestsTests/TestsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Ably

class TestsTests: XCTestCase {

let options: ARTClientOptions! = nil
let options: ClientOptions! = nil

func testAblyWorks() {
var responseData: Data?
Expand Down Expand Up @@ -46,9 +46,9 @@ class TestsTests: XCTestCase {
return
}

let options = ARTClientOptions(key: key as String)
let options = ClientOptions(key: key as String)
options.environment = "sandbox"
let client = ARTRealtime(options: options)
let client = Realtime(options: options)

let receiveExpectation = self.expectation(description: "message received")

Expand All @@ -63,19 +63,19 @@ class TestsTests: XCTestCase {
self.waitForExpectations(timeout: 10, handler: nil)

let backgroundRealtimeExpectation = self.expectation(description: "Realtime in a Background Queue")
var realtime: ARTRealtime! //strong reference
var realtime: Realtime! //strong reference
URLSession.shared.dataTask(with: URL(string: "https://ably.io")!) { _,_,_ in
realtime = ARTRealtime(key: key as String)
realtime = Realtime(key: key as String)
realtime.channels.get("foo").attach { _ in
do { backgroundRealtimeExpectation.fulfill() }
}
} .resume()
self.waitForExpectations(timeout: 10, handler: nil)

let backgroundRestExpectation = self.expectation(description: "Rest in a Background Queue")
var rest: ARTRest! //strong reference
var rest: Rest! //strong reference
URLSession.shared.dataTask(with: URL(string: "https://ably.io")!) { _,_,_ in
rest = ARTRest(key: key as String)
rest = Rest(key: key as String)
rest.channels.get("foo").history { result, error in
do { backgroundRestExpectation.fulfill() }
}
Expand Down
5 changes: 1 addition & 4 deletions Source/ARTURLSessionServerTrust.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ - (instancetype)init:(dispatch_queue_t)queue {
if (self = [super init]) {
_queue = queue;
NSURLSessionConfiguration *config = [NSURLSessionConfiguration ephemeralSessionConfiguration];
#if TARGET_OS_MACCATALYST // if (@available(iOS 13.0, macCatalyst 13.0, ... doesn't help
config.TLSMinimumSupportedProtocolVersion = tls_protocol_version_TLSv12;
#else

config.TLSMinimumSupportedProtocolVersion = tls_protocol_version_TLSv12;

Check warning on line 17 in Source/ARTURLSessionServerTrust.m

View workflow job for this annotation

GitHub Actions / check

'setTLSMinimumSupportedProtocolVersion:' is only available on iOS 13.0 or newer [-Wunguarded-availability-new]

Check failure on line 17 in Source/ARTURLSessionServerTrust.m

View workflow job for this annotation

GitHub Actions / check (tvOS, test_tvOS17_2)

'setTLSMinimumSupportedProtocolVersion:' is only available on tvOS 13.0 or newer [-Werror,-Wunguarded-availability-new]

Check failure on line 17 in Source/ARTURLSessionServerTrust.m

View workflow job for this annotation

GitHub Actions / check (macOS, test_macOS)

'setTLSMinimumSupportedProtocolVersion:' is only available on macOS 10.15 or newer [-Werror,-Wunguarded-availability-new]

Check failure on line 17 in Source/ARTURLSessionServerTrust.m

View workflow job for this annotation

GitHub Actions / check (macOS, test_macOS)

'setTLSMinimumSupportedProtocolVersion:' is only available on macOS 10.15 or newer [-Werror,-Wunguarded-availability-new]
#endif
_session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];
}
return self;
Expand Down
8 changes: 3 additions & 5 deletions Test/Tests/RestClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -278,18 +278,16 @@ class RestClientTests: XCTestCase {
func test__024__RestClient__logging__should_accept_a_custom_logger() throws {
let test = Test()

enum InterceptedLogger {
enum InterceptedLog {
static var interceptedLog: (String, LogLevel) = ("", .none)
}

class MyLogger: Log {

override func log(_ message: String, with level: LogLevel) {
// Default implementation or can be abstract
InterceptedLogger.interceptedLog = (message, level)
InterceptedLog.interceptedLog = (message, level)
}

static var interceptedLog: (String, LogLevel) = ("", .none)
static var interceptedLog: (String, LogLevel) = InterceptedLog.interceptedLog

}

Expand Down

0 comments on commit 421758c

Please sign in to comment.