Skip to content

Commit

Permalink
Fixes (#47)
Browse files Browse the repository at this point in the history
* Resolved #41: Added addAsyncOperation function
* Fixed #44: Replaced serializeSignedRequests with concurencyStrategy
* Project upgrade
* Fixed #45: Using specific version of swiftlint
* Resolved #46: Added prepare-release script
* Removed pods lint and upgraded xcode version
  • Loading branch information
kober32 authored Oct 30, 2023
1 parent 384098d commit cc70d06
Show file tree
Hide file tree
Showing 19 changed files with 277 additions and 88 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ on:
- main
- release/*
pull_request:
schedule:
- cron: '25 6 * * *'

jobs:
build:
name: Build
runs-on: macos-12
runs-on: macos-13
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: Set proper xcode version
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '14.0'
run: sh ./scripts/xcodeselect.sh
- name: Building
run: ./scripts/build.sh
20 changes: 1 addition & 19 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,11 @@ on:
pull_request:

jobs:
pod:
name: Pod Lib Lint
runs-on: macos-12
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: Set proper xcode version
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '14.0'
- name: Build the framework
run: ./scripts/build.sh
- name: Lint
run: pod lib lint --allow-warnings
swift:
name: Swift Lint
runs-on: macos-12
runs-on: macos-13
steps:
- name: Checkout the repo
uses: actions/checkout@v2
- name: Set proper xcode version
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '14.0'
- name: Lint
run: swiftlint --strict
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Carthage/*

*/Pods/*

swiftlint

## Build generated
build/
DerivedData
Expand Down
3 changes: 0 additions & 3 deletions .limedeploy

This file was deleted.

6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// swift-tools-version:5.7
// swift-tools-version:5.9

import PackageDescription

let package = Package(
name: "WultraPowerAuthNetworking",
platforms: [
.iOS(.v11),
.tvOS(.v11)
.iOS(.v12),
.tvOS(.v12)
],
products: [
.library(
Expand Down
13 changes: 13 additions & 0 deletions Sources/WultraPowerauthNetworking/WPNAsyncOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ open class WPNAsyncBlockOperation: WPNAsyncOperation {
}
}

public extension OperationQueue {

/// Creates an asynchonous operation with the execution block and adds to the receiver.
/// - Parameters:
/// - completionQueue: Disatch queue that in which will be the completionblocked called
/// - executionBlock: Block to execute
func addAsyncOperation(_ completionQueue: DispatchQueue? = nil, _ executionBlock: @escaping WPNAsyncBlockOperation.ExecutionBlock) {
let op = WPNAsyncBlockOperation(executionBlock)
op.completionQueue = completionQueue
addOperation(op)
}
}

/// Base class for asynchronous operations that will be put in `OperationQueue`
open class WPNAsyncOperation: Operation, CompletableInSpecificQueue {

Expand Down
2 changes: 1 addition & 1 deletion Sources/WultraPowerauthNetworking/WPNConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation

// Note that this file is autogenerated during release process.
// If you will edit this file, you need to also edit "Deploy/Constants.swift" file
// If you will edit this file, you need to also edit "scripts/deploy/Constants.swift.tpl" file
// inside the root folder.

internal class WPNConstants {
Expand Down
9 changes: 2 additions & 7 deletions Sources/WultraPowerauthNetworking/WPNHttpClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,8 @@ class WPNHttpClient: NSObject, URLSessionDelegate {
}

if let progressCallback = progressCallback {
if #available(iOS 11.0, tvOS 11.0, *) {
observation = task.progress.observe(\.fractionCompleted) { progress, _ in
progressCallback(progress.fractionCompleted)
}
} else {
// iOS 10 (iPhone 5 and older)
progressCallback(-1)
observation = task.progress.observe(\.fractionCompleted) { progress, _ in
progressCallback(progress.fractionCompleted)
}
}
task.resume()
Expand Down
38 changes: 22 additions & 16 deletions Sources/WultraPowerauthNetworking/WPNNetworkingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ import Foundation
import PowerAuth2
import PowerAuthCore

/// Strategy that decides if request will be put in serial or concurent queue.
///
/// More about this topic can be found in the
/// [PowerAuth documentation](https://developers.wultra.com/components/powerauth-mobile-sdk/develop/documentation/PowerAuth-SDK-for-iOS#request-synchronization)
public enum WPNRequestConcurencyStrategy {
/// All requests will be put into concurent queue.
///
/// We recommend not using this option unless you're managing theserialization of requests yourself.
///
/// More about this topic can be found in the
/// [PowerAuth documentation](https://developers.wultra.com/components/powerauth-mobile-sdk/develop/documentation/PowerAuth-SDK-for-iOS#request-synchronization)
case concurentAll
/// Only request that needs PowerAuth signature will be put into serial queue.
case serialSigned
/// All requests will be put into serial queue.
case serialAll
}

/// Networking service for dispatching PowerAuth signed requests.
public class WPNNetworkingService {

Expand All @@ -32,19 +50,10 @@ public class WPNNetworkingService {
/// Response delegate is called on each received response
public weak var responseDelegate: WPNResponseDelegate?

/// Requests that should be signed with the PowerAuth signing will
/// be serialized in the PowerAuth serial queue when the value is `true`.
///
/// Default value is `true`
///
/// With this approach, all signed requests across `WPNNetworkingService` instances using the
/// the same PowerAuth instance (and possibly other classes too) will be serialized into
/// the single serial queue. We recommend leaving this option on unless you're managing the
/// serialization of requests yourself.
/// Strategy that decides if request will be put in serial or concurent queue.
///
/// More about this topic can be found in the
/// [PowerAuth documentation](https://developers.wultra.com/components/powerauth-mobile-sdk/develop/documentation/PowerAuth-SDK-for-iOS#request-synchronization)
public var serializeSignedRequests: Bool = true
/// Default value is `serialSigned`
public var concurencyStrategy = WPNRequestConcurencyStrategy.serialSigned

/// PowerAuth instance that will be used for this networking.
public let powerAuth: PowerAuthSDK
Expand Down Expand Up @@ -76,7 +85,6 @@ public class WPNNetworkingService {
/// - timeoutInterval: Timeout interval of the request.
/// Value from `config` will be used when nil.
/// - progressCallback: Reports fraction of how much data was already transferred.
/// Note that on iOS 10 it will be called once with value -1.
/// - completionQueue: Queue on wich the completion will be executed.
/// Default value is .main
/// - completion: Completion handler. This callback is executed on the queue defined in `completionQueue` parameter.
Expand Down Expand Up @@ -106,7 +114,6 @@ public class WPNNetworkingService {
/// - timeoutInterval: Timeout interval of the request.
/// Value from `config` will be used when nil.
/// - progressCallback: Reports fraction of how much data was already transferred.
/// Note that on iOS 10 it will be called once with value -1.
/// - completionQueue: Queue on wich the completion will be executed.
/// Default value is .main
/// - completion: Completion handler. This callback is executed on the queue defined in `completionQueue` parameter.
Expand Down Expand Up @@ -137,7 +144,6 @@ public class WPNNetworkingService {
/// - timeoutInterval: Timeout interval of the request.
/// Value from `config` will be used when nil.
/// - progressCallback: Reports fraction of how much data was already transferred.
/// Note that on iOS 10 it will be called once with value -1.
/// - completionQueue: Queue on wich the completion will be executed.
/// Default value is .main
/// - completion: Completion handler. This callback is executed on the queue defined in `completionQueue` parameter.
Expand Down Expand Up @@ -251,7 +257,7 @@ public class WPNNetworkingService {

op.completionQueue = completionQueue

if serializeSignedRequests && request.needsSignature {
if (concurencyStrategy == .serialSigned && request.needsSignature) || concurencyStrategy == .serialAll {
// Add operation to the "signing" queue.
if !powerAuth.executeOperation(onSerialQueue: op) {
// Operation wont be added to the queue if there is a missing
Expand Down
24 changes: 5 additions & 19 deletions Sources/WultraPowerauthNetworking/WPNUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,7 @@ internal class WPNConnectionMonitor {
}

var status: Status {
guard #available(iOS 12.0, tvOS 12.0, *), let monitor = self.monitor as? NWPathMonitor else {
// fallback for iOS11 and older. There is no direct way how to easily get the network status without
// some utility class. As this is just a metadata info, we'll do it the best effort way.
return .unknown
}
let path = monitor.currentPath

if path.usesInterfaceType(.cellular) {
return .cellular
} else if path.usesInterfaceType(.wifi) {
Expand All @@ -75,23 +69,15 @@ internal class WPNConnectionMonitor {
}
}

private let monitor: Any?
private let monitor: NWPathMonitor

init() {
if #available(iOS 12.0, tvOS 12.0, *) {
let m = NWPathMonitor()
m.start(queue: .global())
monitor = m
} else {
monitor = nil
}
let m = NWPathMonitor()
m.start(queue: .global())
monitor = m
}

deinit {
if #available(iOS 12.0, tvOS 12.0, *) {
if let monitor = self.monitor as? NWPathMonitor {
monitor.cancel()
}
}
monitor.cancel()
}
}
4 changes: 2 additions & 2 deletions WultraPowerAuthNetworking.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Pod::Spec.new do |s|
s.source = { :git => 'https://github.com/wultra/networking-apple.git', :tag => s.version }
s.source_files = 'Sources/WultraPowerauthNetworking/**/*.swift'
s.platform = :ios
s.swift_version = "5.7"
s.ios.deployment_target = '11.0'
s.swift_version = "5.9"
s.ios.deployment_target = '12.0'

s.dependency 'PowerAuth2', '>= 1.7'
end
22 changes: 15 additions & 7 deletions WultraPowerAuthNetworking.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -164,8 +164,9 @@
OBJ_1 /* Project object */ = {
isa = PBXProject;
attributes = {
BuildIndependentTargetsInParallel = YES;
LastSwiftMigration = 1300;
LastUpgradeCheck = 1340;
LastUpgradeCheck = 1500;
};
buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "WultraPowerAuthNetworking" */;
compatibilityVersion = "Xcode 3.2";
Expand All @@ -190,6 +191,7 @@
/* Begin PBXShellScriptBuildPhase section */
DC3EFA482774A55000C30F64 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
Expand All @@ -204,7 +206,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if ! [ -x \"$(command -v swiftlint)\" ]; then\n echo 'warning: swiftlint is not installed on this computer.' >&2\n exit 0\nfi\n\nswiftlint\n";
shellScript = "\"${PROJECT_DIR}/scripts/swiftlint.sh\" \"-ne\"\n\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down Expand Up @@ -258,6 +260,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_NS_ASSERTIONS = YES;
Expand All @@ -276,7 +279,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
ONLY_ACTIVE_ARCH = YES;
OTHER_SWIFT_FLAGS = "$(inherited) -DXcode";
Expand All @@ -285,7 +288,7 @@
SUPPORTS_MACCATALYST = YES;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) SWIFT_PACKAGE DEBUG";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TVOS_DEPLOYMENT_TARGET = 10.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
USE_HEADERMAP = NO;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
Expand All @@ -295,6 +298,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
ENABLE_TESTABILITY = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -316,13 +320,15 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)";
SWIFT_VERSION = 5.0;
TARGET_NAME = WultraPowerAuthNetworking;
TVOS_DEPLOYMENT_TARGET = 12.0;
};
name = Debug;
};
OBJ_35 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CURRENT_PROJECT_VERSION = 1;
DEAD_CODE_STRIPPING = YES;
ENABLE_TESTABILITY = YES;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -344,6 +350,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited)";
SWIFT_VERSION = 5.0;
TARGET_NAME = WultraPowerAuthNetworking;
TVOS_DEPLOYMENT_TARGET = 12.0;
};
name = Release;
};
Expand Down Expand Up @@ -372,6 +379,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = YES;
DEAD_CODE_STRIPPING = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -387,7 +395,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MACOSX_DEPLOYMENT_TARGET = 10.15;
OTHER_SWIFT_FLAGS = "$(inherited) -DXcode";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -396,7 +404,7 @@
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "$(inherited) SWIFT_PACKAGE";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
TVOS_DEPLOYMENT_TARGET = 10.0;
TVOS_DEPLOYMENT_TARGET = 12.0;
USE_HEADERMAP = NO;
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1340"
LastUpgradeVersion = "1500"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
File renamed without changes.
Loading

0 comments on commit cc70d06

Please sign in to comment.