Skip to content

Commit

Permalink
[lint] run swiftlint --fix
Browse files Browse the repository at this point in the history
Fixes spacing, non-logic items
  • Loading branch information
nan-li committed May 6, 2024
1 parent b6488ba commit cc06e25
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import OneSignalLiveActivities
public struct ContentState: OneSignalLiveActivityContentState {
// Dynamic stateful properties about your activity go here!
var message: String

var onesignal: OneSignalLiveActivityContentStateData?
}

Expand All @@ -62,7 +62,7 @@ import OneSignalLiveActivities
var status: String
var progress: Double
var bugs: Int

var onesignal: OneSignalLiveActivityContentStateData?
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class LiveActivityController: NSObject {
// This is mostly for cross-platform SDKs and allows OneSignal to handle everything but the
// creation of the Widget Extension.
OneSignal.LiveActivities.setupDefault()

if #available(iOS 17.2, *) {
// ExampleAppThirdWidgetAttributes is an example of how to manually set up LA.
// Setup an async task to monitor and send pushToStartToken updates to OneSignalSDK.
Expand Down Expand Up @@ -109,11 +109,11 @@ class LiveActivityController: NSObject {
if #available(iOS 16.1, *) {
let attributeData: [String: Any] = ["title": "in-app-title"]
let contentData: [String: Any] = ["message": ["en": "HELLO", "es": "HOLA"], "progress": 0.58, "status": "1/15", "bugs": 2]

OneSignal.LiveActivities.startDefault(activityId, attributes: attributeData, content: contentData)
}
}

/**
An example of starting a Live Activity whose attributes are **not** "OneSignal SDK aware". The app must handle listening for update tokens and notify the OneSignal SDK.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import Foundation
*/
@frozen public struct AnyCodable: Codable {
public let value: Any

public func asBool() -> Bool? { return value as? Bool }
public func asInt() -> Int? { return value as? Int }
public func asDouble() -> Double? { return value as? Double }
public func asString() -> String? { return value as? String }
public func asArray() -> [AnyCodable]? { return value as? [AnyCodable] }
public func asDict() -> [String : AnyCodable]? { return value as? [String : AnyCodable] }
public func asDict() -> [String: AnyCodable]? { return value as? [String: AnyCodable] }

public init<T>(_ value: T?) {
self.value = value ?? ()
}

public init(nilLiteral _: ()) {
self.init(nil as Any?)
}
Expand Down Expand Up @@ -57,7 +57,7 @@ import Foundation
public init(dictionaryLiteral elements: (AnyHashable, Any)...) {
self.init([AnyHashable: Any](elements, uniquingKeysWith: { first, _ in first }))
}

public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()

Expand Down Expand Up @@ -85,7 +85,7 @@ import Foundation
throw DecodingError.dataCorruptedError(in: container, debugDescription: "AnyCodable value cannot be decoded")
}
}

public func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()

Expand Down Expand Up @@ -146,7 +146,7 @@ import Foundation

#if canImport(Foundation)
private func encode(nsnumber: NSNumber, into container: inout SingleValueEncodingContainer) throws {
switch Character(Unicode.Scalar(UInt8(nsnumber.objCType.pointee))) {
switch Character(Unicode.Scalar(UInt8(nsnumber.objCType.pointee))) {
case "B":
try container.encode(nsnumber.boolValue)
case "c":
Expand Down Expand Up @@ -263,7 +263,6 @@ extension AnyCodable: ExpressibleByStringInterpolation {}
extension AnyCodable: ExpressibleByArrayLiteral {}
extension AnyCodable: ExpressibleByDictionaryLiteral {}


extension AnyCodable: Hashable {
public func hash(into hasher: inout Hasher) {
switch value {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class OSLiveActivitiesExecutor: OSPushSubscriptionObserver {
if state.previous.id == state.current.id {
return
}

// when a push subscription id changes, we need to re-send up all update and start tokens with the new ID.
self.requestDispatch.async {
self.caches { _ in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public extension OSLiveActivities {
static func setupDefault(options: LiveActivitySetupOptions? = nil) {
OneSignalLiveActivitiesManagerImpl.setupDefault(options: options)
}

/**
Start a new LiveActivity that is modelled by the default`DefaultLiveActivityAttributes` structure. The `DefaultLiveActivityAttributes`
is initialized with the dynamic `attributes` and `content` passed in.
Expand All @@ -87,7 +87,7 @@ public extension OSLiveActivities {
- content: A dictionary of the initital content state passed into `DefaultLiveActivityAttributes`.
*/
@available(iOS 16.1, *)
static func startDefault(_ activityId: String, attributes: [String : Any], content: [String : Any]) {
static func startDefault(_ activityId: String, attributes: [String: Any], content: [String: Any]) {
OneSignalLiveActivitiesManagerImpl.startDefault(activityId, attributes: attributes, content: content)
}
}
Expand All @@ -96,7 +96,7 @@ public extension OSLiveActivities {
The setup options for `OneSignal.LiveActivities.setup`.
*/
@objc(LiveActivitySetupOptions)
public class LiveActivitySetupOptions : NSObject {
public class LiveActivitySetupOptions: NSObject {
/**
When true, OneSignal will listen for pushToStart tokens for the `OneSignalLiveActivityAttributes` structure.
*/
Expand All @@ -109,7 +109,7 @@ public class LiveActivitySetupOptions : NSObject {
*/
@objc
public var enablePushToUpdate: Bool = true

@objc
public init(enablePushToStart: Bool = true, enablePushToUpdate: Bool = true) {
self.enablePushToStart = enablePushToStart
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,19 @@ public class OneSignalLiveActivitiesManagerImpl: NSObject, OSLiveActivities {
@available(iOS 17.2, *)
public static func setPushToStartToken(_ activityType: String, withToken: String) throws {
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignal.LiveActivities setStartToken called with activityType: \(activityType) token: \(withToken)")

guard let activityType = activityType.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlUserAllowed) else {
throw LiveActivitiesError.invalidActivityType("Cannot translate activity type to url encoded string.")
}

_executor.append(OSRequestSetStartToken(key: activityType, token: withToken))
}

@objc
@available(iOS 17.2, *)
public static func removePushToStartToken(_ activityType: String) throws {
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignal.LiveActivities removeStartToken called with activityType: \(activityType)")

guard let activityType = activityType.addingPercentEncoding(withAllowedCharacters: NSCharacterSet.urlUserAllowed) else {
throw LiveActivitiesError.invalidActivityType("Cannot translate activity type to url encoded string.")
}
Expand Down Expand Up @@ -138,28 +138,28 @@ public class OneSignalLiveActivitiesManagerImpl: NSObject, OSLiveActivities {
}
listenForActivity(activityType, options: options)
}

@objc
@available(iOS 16.1, *)
public static func setupDefault(options: LiveActivitySetupOptions? = nil) {
setup(DefaultLiveActivityAttributes.self, options: options)
}

@objc
@available(iOS 16.1, *)
public static func startDefault(_ activityId: String, attributes: [String : Any], content: [String : Any]) {
public static func startDefault(_ activityId: String, attributes: [String: Any], content: [String: Any]) {
let oneSignalAttribute = OneSignalLiveActivityAttributeData.create(activityId: activityId)

var attributeData = [String: AnyCodable]()
for attribute in attributes {
attributeData.updateValue(AnyCodable(attribute.value), forKey: attribute.key)
}

var contentData = [String: AnyCodable]()
for contentItem in content {
contentData.updateValue(AnyCodable(contentItem.value), forKey: contentItem.key)
}

let attributes = DefaultLiveActivityAttributes(data: attributeData, onesignal: oneSignalAttribute)
let contentState = DefaultLiveActivityAttributes.ContentState(data: contentData)
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class OSRequestRemoveUpdateToken: OneSignalRequest, OSLiveActivityRequest, OSLiv
OneSignalLog.onesignalLog(.LL_DEBUG, message: "Cannot translate activity type to url encoded string.")
return false
}

// self.path = "apps/\(appId)/activities/tokens/update/\(activityId)/subscriptions/\(subscriptionId)"
self.path = "apps/\(appId)/live_activities/\(activityId)/token/\(subscriptionId)"
self.method = DELETE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class OSRequestSetStartToken: OneSignalRequest, OSLiveActivityRequest, OSLiveAct
OneSignalLog.onesignalLog(.LL_DEBUG, message: "Cannot translate activity type to url encoded string.")
return false
}

self.path = "apps/\(appId)/activities/tokens/start/\(activityType)/subscriptions/\(subscriptionId)"
self.parameters = ["activity_token": self.token, "device_type": 0]
self.method = PUT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ final class DefaultLiveActivityAttributesTests: XCTestCase {
}
}
""".data(using: .utf8)!

/* When */
let decoder = JSONDecoder()
let sut = try decoder.decode(DefaultLiveActivityAttributes.self, from: json)
Expand Down Expand Up @@ -113,7 +113,7 @@ final class DefaultLiveActivityAttributesTests: XCTestCase {
XCTAssertEqual(sut.data["dictValue"]?.asDict()?["anotherDict"]?.asDict()?["intValue"]?.asInt(), 7)
XCTAssertEqual(sut.onesignal.activityId, "my-activity-id")
}

func testProperDecodingOfAttributesWithExtraOneSignalParameters() throws {
/* Setup */
let json = """
Expand All @@ -126,40 +126,40 @@ final class DefaultLiveActivityAttributesTests: XCTestCase {
}
}
""".data(using: .utf8)!

/* When */
let decoder = JSONDecoder()
_ = try decoder.decode(DefaultLiveActivityAttributes.self, from: json)

/* Then */
// not blowing up is a passed test
}

func testEmptyAttributesPayloadThrowsError() {
/* Setup */
let json = """
{
}
""".data(using: .utf8)!

/* When/Then */
let decoder = JSONDecoder()
XCTAssertThrowsError(try decoder.decode(DefaultLiveActivityAttributes.self, from: json))
}

func testMissingDataInAttributesPayloadThrowsError() {
/* Setup */
let json = """
{
"notData": {}
}
""".data(using: .utf8)!

/* When/Then */
let decoder = JSONDecoder()
XCTAssertThrowsError(try decoder.decode(DefaultLiveActivityAttributes.self, from: json))
}

func testProperDecodingOfContentStatePayload() throws {
/* Setup */
let json = """
Expand Down Expand Up @@ -192,7 +192,7 @@ final class DefaultLiveActivityAttributesTests: XCTestCase {
}
}
""".data(using: .utf8)!

/* When */
let decoder = JSONDecoder()
let sut = try decoder.decode(DefaultLiveActivityAttributes.ContentState.self, from: json)
Expand Down Expand Up @@ -233,7 +233,7 @@ final class DefaultLiveActivityAttributesTests: XCTestCase {
XCTAssertEqual(sut.data["dictValue"]?.asDict()?["anotherDict"]?.asDict()?["intValue"]?.asInt(), 7)
XCTAssertNil(sut.onesignal)
}

func testProperDecodingOfContentStateWithOneSignalPayload() throws {
/* Setup */
let json = """
Expand All @@ -245,15 +245,15 @@ final class DefaultLiveActivityAttributesTests: XCTestCase {
}
}
""".data(using: .utf8)!

/* When */
let decoder = JSONDecoder()
let sut = try decoder.decode(DefaultLiveActivityAttributes.ContentState.self, from: json)

/* Then */
XCTAssertEqual(sut.onesignal?.notificationId, "my-notification-id")
}

func testProperDecodingOfContentStateWithExtraOneSignalParameters() throws {
/* Setup */
let json = """
Expand All @@ -266,35 +266,35 @@ final class DefaultLiveActivityAttributesTests: XCTestCase {
}
}
""".data(using: .utf8)!

/* When */
let decoder = JSONDecoder()
_ = try decoder.decode(DefaultLiveActivityAttributes.ContentState.self, from: json)

/* Then */
// not blowing up is a passed test
}

func testEmptyContentStatePayloadThrowsError() {
/* Setup */
let json = """
{
}
""".data(using: .utf8)!

/* When/Then */
let decoder = JSONDecoder()
XCTAssertThrowsError(try decoder.decode(DefaultLiveActivityAttributes.ContentState.self, from: json))
}

func testMissingDataInContentStatePayloadThrowsError() {
/* Setup */
let json = """
{
"notData": {}
}
""".data(using: .utf8)!

/* When/Then */
let decoder = JSONDecoder()
XCTAssertThrowsError(try decoder.decode(DefaultLiveActivityAttributes.ContentState.self, from: json))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@
import OneSignalCore

public class OSStubLiveActivities: NSObject, OSLiveActivities {

@objc
public static func liveActivities() -> AnyClass {
return OSStubLiveActivities.self
}

public static func enter(_ activityId: String, withToken: String) {
OneSignalLog.onesignalLog(.LL_ERROR, message: "OneSignalLiveActivities not found. In order to use OneSignal's LiveActivities features the OneSignalLiveActivities module must be added.")
}

public static func enter(_ activityId: String, withToken: String, withSuccess: OSResultSuccessBlock?, withFailure: OSFailureBlock?) {
OneSignalLog.onesignalLog(.LL_ERROR, message: "OneSignalLiveActivities not found. In order to use OneSignal's LiveActivities features the OneSignalLiveActivities module must be added.")
}

public static func exit(_ activityId: String) {
OneSignalLog.onesignalLog(.LL_ERROR, message: "OneSignalLiveActivities not found. In order to use OneSignal's LiveActivities features the OneSignalLiveActivities module must be added.")
}

public static func exit(_ activityId: String, withSuccess: OSResultSuccessBlock?, withFailure: OSFailureBlock?) {
OneSignalLog.onesignalLog(.LL_ERROR, message: "OneSignalLiveActivities not found. In order to use OneSignal's LiveActivities features the OneSignalLiveActivities module must be added.")
}

}
Loading

0 comments on commit cc06e25

Please sign in to comment.