Skip to content

Commit

Permalink
Merge pull request #90 from TiagoBrasN/lower-deployment-target
Browse files Browse the repository at this point in the history
Lower deployment target
  • Loading branch information
mariusc authored Jan 27, 2021
2 parents 581650c + 7f6f14f commit 78ffa3f
Show file tree
Hide file tree
Showing 15 changed files with 188 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "nodes-ios/TranslationManager" "3.1.1"
github "nodes-ios/TranslationManager" "3.1.3"
6 changes: 3 additions & 3 deletions NStackSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'NStackSDK'
s.version = '5.1.4'
s.version = '5.1.5'
s.summary = 'NStackSDK is the companion software development kit to the NStack backend.'

# This description is used to generate tags and improve search results.
Expand All @@ -25,11 +25,11 @@ Pod::Spec.new do |s|
s.author = { "Nodes Agency - iOS" => "ios@nodes.dk" }
s.source = { :git => 'https://github.com/nstack-io/nstack-ios-sdk', :tag => s.version.to_s }

s.ios.deployment_target = "11"
s.ios.deployment_target = "9.0"
s.swift_version = '5.2'

s.default_subspecs = "Core"
s.dependency 'NLocalizationManager'
s.dependency 'NLocalizationManager', '~> 3.0'

s.subspec 'Core' do |core|
core.source_files = [ 'NStackSDK/**/*.swift']
Expand Down
77 changes: 53 additions & 24 deletions NStackSDK.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

42 changes: 36 additions & 6 deletions NStackSDK/Classes/NStack Manager/ConnectionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import Foundation
#if os(macOS)
import AppKit
#elseif os(watchOS)
import WatchKit
#else
import UIKit
#endif
Expand Down Expand Up @@ -332,10 +334,36 @@ extension ConnectionManager {
// MARK: - FeedbackRepository
extension ConnectionManager {
private func getPlatform() -> String {
#if os(iOS) || os(tvOS)
switch UIDevice.current.systemName.lowercased() {
case "ios": return "ios"
default: return "unknown"
}
#elseif os(macOS)
return ProcessInfo.processInfo.operatingSystemVersionString.lowercased()
#elseif os(watchOS)
return WKInterfaceDevice.current().systemName.lowercased()
#endif
}

private func modelType() -> String {
#if os(iOS) || os(tvOS)
return UIDevice.current.modelType.rawValue
#elseif os(macOS)
return "unknown"
#elseif os(watchOS)
return WKInterfaceDevice.current().model
#endif
}

private func systemVersion() -> String {
#if os(iOS) || os(tvOS)
return UIDevice.current.systemVersion
#elseif os(macOS)
return "unknown"
#elseif os(watchOS)
return WKInterfaceDevice.current().systemVersion
#endif
}

func provideFeedback(_ feedback: Feedback, completion: @escaping Completion<Void>) {
Expand All @@ -346,19 +374,21 @@ extension ConnectionManager {
urlRequest.allHTTPHeaderFields = defaultHeaders
urlRequest.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

let data = MultipartBuilder(boundary: boundary)
let builder = MultipartBuilder(boundary: boundary)
.append(name: "type", value: feedback.type.rawValue)
.append(name: "platform", value: getPlatform())
.append(name: "os", value: UIDevice.current.systemVersion)
.append(name: "device", value: UIDevice.current.modelType.rawValue)
.append(name: "os", value: systemVersion())
.append(name: "device", value: modelType())
.append(name: "app_version", value: feedback.appVersion)
.append(name: "name", value: feedback.name)
.append(name: "email", value: feedback.email)
.append(name: "message", value: feedback.message)
.append(name: "image", image: feedback.image, jpegQuality: 0.7)
.build()

#if canImport(UIKit)
builder.append(name: "image", image: feedback.image, jpegQuality: 0.7)
#endif

session.uploadTask(with: urlRequest, from: data, completionHandler: { _, _, error in
session.uploadTask(with: urlRequest, from: builder.build(), completionHandler: { _, _, error in
if let error = error {
completion(.failure(error))
} else {
Expand Down
2 changes: 1 addition & 1 deletion NStackSDK/Classes/Notify/AlertManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class AlertManager {
}

public var requestReview: () -> Void = {
if #available(iOSApplicationExtension 10.3, *) {
if #available(iOS 10.3, *) {
#if os(iOS)
SKStoreReviewController.requestReview()
#endif
Expand Down
2 changes: 1 addition & 1 deletion NStackSDK/Classes/Notify/StoreReviewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import StoreKit

class StoreReviewManager {
static func requestReview() {
if #available(iOSApplicationExtension 10.3, *) {
if #available(iOS 10.3, *) {
SKStoreReviewController.requestReview()
}
}
Expand Down
19 changes: 17 additions & 2 deletions NStackSDK/Classes/Other/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ extension String {
}
}

@available(iOS 10.0, OSX 10.12, *)
extension ISO8601DateFormatter {
convenience init(_ formatOptions: Options, timeZone: TimeZone = TimeZone(secondsFromGMT: 0)!) {
self.init()
Expand All @@ -34,11 +35,25 @@ extension ISO8601DateFormatter {
}

extension Formatter {
static let iso8601 = ISO8601DateFormatter([.withInternetDateTime])
@available(iOS 10.0, OSX 10.12, *)
static let iso8601: ISO8601DateFormatter = ISO8601DateFormatter([.withInternetDateTime])

static let iso8601Fallback: DateFormatter = {
let formatter = DateFormatter()
formatter.calendar = Calendar(identifier: .iso8601)
formatter.locale = Locale(identifier: "en_US_POSIX")
formatter.timeZone = TimeZone(secondsFromGMT: 0)
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssXXXXX"
return formatter
}()
}

extension Date {
var iso8601: String {
return DateFormatter.iso8601.string(from: self)
if #available(iOS 10.0, OSX 10.12, *) {
return DateFormatter.iso8601.string(from: self)
} else {
return DateFormatter.iso8601Fallback.string(from: self)
}
}
}
6 changes: 6 additions & 0 deletions NStackSDK/Classes/Other/MultipartBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
// Copyright © 2019 Nodes ApS. All rights reserved.
//

import Foundation
#if canImport(UIKit)
import UIKit
#endif

class MultipartBuilder {
struct Part: Hashable {
Expand All @@ -23,6 +26,7 @@ class MultipartBuilder {
self.boundary = boundary
}

#if canImport(UIKit)
/// Appends image field if value != nil. If there's already field with the same name,
/// that field will be replaced.
/// - Parameter name: field's name.
Expand All @@ -38,6 +42,8 @@ class MultipartBuilder {

return self
}
#endif


/// Appends field if value != nil. If there's already field with the same name,
/// that field will be replaced.
Expand Down
2 changes: 1 addition & 1 deletion NStackSDK/Classes/Other/N-Meta.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private func userAgentString(environment: String) -> String {
appendString += "\(UIDevice.current.modelName)"
#elseif os(watchOS)
appendString += "\(WKInterfaceDevice.current().systemVersion);"
appendString += "\(WKInterfaceDevice.current().codable)"
appendString += "\(WKInterfaceDevice.current().model)"
#elseif os(macOS)

#endif
Expand Down
5 changes: 5 additions & 0 deletions NStackSDK/Feedback.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
// Copyright © 2019 Nodes ApS. All rights reserved.
//

import Foundation
#if canImport(UIKit)
import UIKit
#endif

public enum FeedbackType: String {
case feedback, bug
Expand All @@ -23,6 +26,8 @@ struct Feedback {
var name: String?
var email: String?
var message: String?
#if canImport(UIKit)
var image: UIImage?
#endif
var breadcrumbs: Breadcrumbs?
}
31 changes: 31 additions & 0 deletions NStackSDK/FeedbackManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
// Copyright © 2019 Nodes ApS. All rights reserved.
//

import Foundation
#if canImport(UIKit)
import UIKit
#endif

public class FeedbackManager {
// MARK: - Properties
Expand All @@ -17,6 +20,7 @@ public class FeedbackManager {
self.repository = repository
}

#if canImport(UIKit)
/// Sends app feedback.
///
/// - Parameter type: Feedback type, can be either **bug** or **feedback**.
Expand Down Expand Up @@ -44,4 +48,31 @@ public class FeedbackManager {

repository.provideFeedback(feedback, completion: completion)
}
#endif

/// Sends app feedback.
///
/// - Parameter type: Feedback type, can be either **bug** or **feedback**.
/// - Parameter appVersion: App Version.
/// - Parameter message: Content of the feedback, eg, explaining a bug.
/// - Parameter name: Reporter's name.
/// - Parameter email: Reporter's email.
/// - Parameter completion: Completion block when the API call has finished.
public func provideFeedback(
type: FeedbackType,
appVersion: String,
message: String,
name: String? = nil,
email: String? = nil,
completion: @escaping (Result<Void>) -> Void) {

let feedback = Feedback(
type: type,
appVersion: appVersion,
name: name,
email: email,
message: message)

repository.provideFeedback(feedback, completion: completion)
}
}
2 changes: 1 addition & 1 deletion NStackSDK/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>4.0.10</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
4 changes: 2 additions & 2 deletions NStackSDK/Views/Proposals/ProposalViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ extension ProposalViewController: UITableViewDelegate, UITableViewDataSource {
}

// MARK: Swipe actions for +iOS 11
@available(iOSApplicationExtension 11.0, *)
@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let deleteAction = setupAction(forRowAt: indexPath)
let swipeConfig = UISwipeActionsConfiguration(actions: [deleteAction])
return swipeConfig
}

@available(iOSApplicationExtension 11.0, *)
@available(iOS 11.0, *)
private func setupAction(forRowAt indexPath: IndexPath) -> UIContextualAction {
let action = UIContextualAction(style: .destructive, title: "Delete") {(_: UIContextualAction, _: UIView, completionHandler: @escaping (Bool) -> Void) in
self.presenter.handle(.deleteProposal(section: indexPath.section, index: indexPath.row))
Expand Down
28 changes: 28 additions & 0 deletions NStackSDKTests/DateFormatterTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// DateFormatterTests.swift
// NStackSDK
//
// Created by Tiago Bras on 27/01/2021.
// Copyright © 2021 Nodes ApS. All rights reserved.
//

import XCTest
@testable import NStackSDK

class DateFormatterTests: XCTestCase {

func testISO8061DateFormatter() throws {
let expectedDate = Date(timeIntervalSince1970: 1611749050)

if #available(iOS 10.0, OSX 10.12, *) {
XCTAssertEqual(DateFormatter.iso8601.date(from: "2021-01-27T12:04:10Z"), expectedDate)
XCTAssertEqual(DateFormatter.iso8601.date(from: "2021-01-27T13:04:10+01:00"), expectedDate)
XCTAssertNil(DateFormatter.iso8601.date(from: "2021-01T13:04:10-41:00"))
}

XCTAssertEqual(DateFormatter.iso8601Fallback.date(from: "2021-01-27T12:04:10Z"), expectedDate)
XCTAssertEqual(DateFormatter.iso8601Fallback.date(from: "2021-01-27T13:04:10+01:00"), expectedDate)
XCTAssertNil(DateFormatter.iso8601Fallback.date(from: "2021-01T13:04:10-41:00"))
}

}
2 changes: 2 additions & 0 deletions NStackSDKTests/NStackTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ class NStackTests: XCTestCase {
waitForExpectations(timeout: 5.0)
}

#if canImport(UIKit)
func testFeedbackImageUpload() {
let exp = expectation(description: "Image upload")

Expand All @@ -168,4 +169,5 @@ class NStackTests: XCTestCase {

self.wait(for: [exp], timeout: 20)
}
#endif
}

0 comments on commit 78ffa3f

Please sign in to comment.