Skip to content

Commit

Permalink
Merge pull request #473 from mindbox-cloud/release/2.11.2
Browse files Browse the repository at this point in the history
Release/2.11.2
  • Loading branch information
AndreyEmtsov authored Dec 4, 2024
2 parents a9e2f4d + ad2ac0e commit 3789f5d
Show file tree
Hide file tree
Showing 305 changed files with 5,320 additions and 3,362 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ on:
tags-ignore:
- '**'
jobs:
SwiftLint:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: cirruslabs/swiftlint-action@v1
with:
args: --config .swiftlint.yml

build:
runs-on: macos-latest
timeout-minutes: 15
Expand Down
145 changes: 145 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Directory and file filters
included: # paths to include during linting. `--path` is ignored if present.
- Mindbox
- MindboxLogger
- MindboxNotifications
- MindboxTests
- MindboxNotificationsTests
excluded: # paths to ignore during linting. Takes precedence over `included`.

only_rules: # default rules
- closing_brace
- closure_parameter_position
- colon
- comma
- comment_spacing
- compiler_protocol_init
- computed_accessors_order
- control_statement
- cyclomatic_complexity
- deployment_target
- discouraged_direct_init
- duplicate_conditions
- duplicate_enum_cases
- duplicate_imports
- empty_enum_arguments
- empty_parameters
- empty_parentheses_with_trailing_closure
- file_length
- for_where
- force_cast
- force_try
- function_body_length
- function_parameter_count
- generic_type_name
- implicit_getter
- inclusive_language
- invalid_swiftlint_command
- is_disjoint
- large_tuple
- leading_whitespace
- legacy_cggeometry_functions
- legacy_constant
- legacy_constructor
- legacy_hashing
- legacy_nsgeometry_functions
- legacy_random
- line_length
- mark
- multiple_closures_with_trailing_closure
- no_space_in_method_call
- non_optional_string_data_conversion
- notification_center_detachment
- ns_number_init_as_function_reference
- nsobject_prefer_isequal
- opening_brace
- operator_whitespace
- optional_data_string_conversion
- orphaned_doc_comment
- prefer_type_checking
- private_unit_test
- protocol_property_accessors_order
- reduce_boolean
- redundant_discardable_let
- redundant_objc_attribute
- redundant_optional_initialization
- redundant_set_access_control
- redundant_string_enum_value
- redundant_void_return
- return_arrow_whitespace
- self_in_property_initialization
- shorthand_operator
- statement_position
- static_over_final_class
- superfluous_disable_command
- syntactic_sugar
- trailing_comma
- trailing_newline
- trailing_semicolon
- trailing_whitespace
- unavailable_condition
- unneeded_break_in_switch
- unneeded_override
- unneeded_synthesized_initializer
- unused_closure_parameter
- unused_control_flow_label
- unused_enumerated
- unused_optional_binding
- unused_setter_value
- vertical_parameter_alignment
- vertical_whitespace
- void_function_in_ternary
- void_return
- xctfail_message

# opt_in_rules
- attributes
- closure_body_length
- closure_end_indentation
- closure_spacing
- discouraged_object_literal
- empty_count
- empty_string
- fatal_error_message
- first_where
- force_unwrapping
- last_where
- modifier_order
- operator_usage_whitespace
- private_outlet
- redundant_type_annotation
- toggle_bool
- unneeded_parentheses_in_closure_argument
- vertical_whitespace_closing_braces
- weak_delegate
- yoda_condition

# Default Rules Setup

cyclomatic_complexity:
ignores_case_statements: true

file_length:
warning: 400
error: 800
ignore_comment_only_lines: true

function_body_length:
warning: 150
error: 250

large_tuple:
warning: 3
error: 4

line_length:
warning: 220
error: 300
ignores_comments: true
ignores_function_declarations: true

# Opt-in Rules Setup

closure_body_length:
warning: 30
error: 50
10 changes: 10 additions & 0 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
474F37A32C16F5B000F38BB0 /* NotificationCenterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationCenterView.swift; sourceTree = "<group>"; };
474F37AD2C170FB600F38BB0 /* NotificationCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationCellView.swift; sourceTree = "<group>"; };
477480792C174BAA00580FB2 /* Payload.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Payload.swift; sourceTree = "<group>"; };
47912FD92CB42D640063387D /* AppDelegate_IDFA.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate_IDFA.swift; sourceTree = "<group>"; };
47D63E2C2C2EAD220055E7D8 /* Mindbox.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Mindbox.framework; sourceTree = BUILT_PRODUCTS_DIR; };
47FFE2252C187D3C0007E2F6 /* SwiftDataManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftDataManager.swift; sourceTree = "<group>"; };
4AF2BFD8ABA97C73F589C5DB /* Pods_MindboxNotificationServiceExtension.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_MindboxNotificationServiceExtension.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -164,6 +165,7 @@
0AEDBC6D2BB6F8F200EE8722 = {
isa = PBXGroup;
children = (
47912FD82CB4130C0063387D /* Samples */,
0AEDBC782BB6F8F200EE8722 /* Example */,
0A0DE3462BB8455A00812E73 /* MindboxNotificationServiceExtension */,
0AD271D32BB9D81E00750279 /* MindboxNotificationContentExtension */,
Expand Down Expand Up @@ -256,6 +258,14 @@
path = ChooseInAppMessagesDelegate;
sourceTree = "<group>";
};
47912FD82CB4130C0063387D /* Samples */ = {
isa = PBXGroup;
children = (
47912FD92CB42D640063387D /* AppDelegate_IDFA.swift */,
);
path = Samples;
sourceTree = "<group>";
};
47FFE2242C187D360007E2F6 /* Services */ = {
isa = PBXGroup;
children = (
Expand Down
39 changes: 16 additions & 23 deletions Example/Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,40 @@
//

import Mindbox
import Foundation
import UIKit

@main
class AppDelegate: MindboxAppDelegate {
final class AppDelegate: MindboxAppDelegate {

//https://developers.mindbox.ru/docs/ios-sdk-initialization
// https://developers.mindbox.ru/docs/ios-sdk-initialization
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
super.application(application, didFinishLaunchingWithOptions: launchOptions)

do {
// To run the application on a physical device you need to change the endpoint
// You should also change the application bundle ID in all targets, more details in the readme
// You can still run the application on the simulator to see In-Apps
let mindboxSdkConfig = try MBConfiguration(
//To run the application on a physical device you need to change the endpoint
//You should also change the application bundle ID in all targets, more details in the readme
//You can still run the application on the simulator to see In-Apps
endpoint: "Mpush-test.ReleaseExample.IosApp",
domain: "api.mindbox.ru",
subscribeCustomerIfCreated: true,
shouldCreateCustomer: true
)
Mindbox.shared.initialization(configuration: mindboxSdkConfig)
} catch {
print(error)
} catch {
print(error.localizedDescription)
}
//https://developers.mindbox.ru/docs/ios-send-push-notifications-appdelegate

// https://developers.mindbox.ru/docs/ios-send-push-notifications-appdelegate
registerForRemoteNotifications()

return true
}

func application(
_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions
) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}

//https://developers.mindbox.ru/docs/ios-send-push-notifications-appdelegate
// https://developers.mindbox.ru/docs/ios-send-push-notifications-appdelegate
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
Expand All @@ -56,13 +49,13 @@ class AppDelegate: MindboxAppDelegate {
completionHandler([.list, .badge, .sound, .banner])
}

//https://developers.mindbox.ru/docs/ios-sdk-handle-tap
// https://developers.mindbox.ru/docs/ios-sdk-handle-tap
override func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
//https://developers.mindbox.ru/docs/ios-sdk-methods
// https://developers.mindbox.ru/docs/ios-sdk-methods
print("Is mindbox notification: \(Mindbox.shared.isMindboxPush(userInfo: response.notification.request.content.userInfo))")
if let mindboxPushNotification = Mindbox.shared.getMindboxPushData(userInfo: response.notification.request.content.userInfo),
Mindbox.shared.isMindboxPush(userInfo: response.notification.request.content.userInfo),
Expand All @@ -73,13 +66,13 @@ class AppDelegate: MindboxAppDelegate {
super.userNotificationCenter(center, didReceive: response, withCompletionHandler: completionHandler)
}

//https://developers.mindbox.ru/docs/ios-send-push-notifications-appdelegate
// https://developers.mindbox.ru/docs/ios-send-push-notifications-appdelegate
func registerForRemoteNotifications() {
UNUserNotificationCenter.current().delegate = self
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
UNUserNotificationCenter.current().requestAuthorization(options: [ .alert, .sound, .badge]) { granted, error in
print("Permission granted: \(granted)")
print("Permission granted to allow local and remote notifications for your app: \(granted)")
if let error = error {
print("NotificationsRequestAuthorization failed with error: \(error.localizedDescription)")
}
Expand Down
2 changes: 2 additions & 0 deletions Example/Example/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSUserTrackingUsageDescription</key>
<string>This identifier will be used to deliver personalized ads to you.</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand Down
3 changes: 1 addition & 2 deletions Example/Example/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import UIKit
import SwiftUI

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
final class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?

Expand All @@ -26,4 +26,3 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
window.makeKeyAndVisible()
}
}

22 changes: 22 additions & 0 deletions Example/Example/Services/SwiftDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public struct SwiftDataManager {
}

private init() {
SwiftDataManager.createDirectoryForSwiftData()

let schema = Schema([
Item.self,
])
Expand Down Expand Up @@ -59,6 +61,26 @@ public struct SwiftDataManager {
}
}
}

private static func createDirectoryForSwiftData() {
let fileManager = FileManager.default
let appGroupIdentifier = "group.cloud.Mindbox.cloud.Mindbox.ReleaseExampleIos"
if let appGroupURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: appGroupIdentifier) {
let applicationSupportURL = appGroupURL.appendingPathComponent("Library/Application Support")

if !fileManager.fileExists(atPath: applicationSupportURL.path) {
do {
try fileManager.createDirectory(at: applicationSupportURL, withIntermediateDirectories: true, attributes: nil)
} catch {
print("Failed to create Application Support directory: \(error)")
}
} else {
print("Application Support directory already exists at \(applicationSupportURL.path)")
}
} else {
fatalError("Could not find App Group container URL.")
}
}
}

private extension SwiftDataManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ import Mindbox
class ChooseInAppMessagesDelegate: InAppMessagesDelegate {

private init() {}
static var shared = ChooseInAppMessagesDelegate()
static let shared = ChooseInAppMessagesDelegate()

//https://developers.mindbox.ru/docs/in-app
// https://developers.mindbox.ru/docs/in-app
func inAppMessageTapAction(id: String, url: URL?, payload: String) {
//Here you can add your custom logic
print("inAppMessageTapAction")
print(id)
print(url ?? "")
print(payload)
print("InApp ID: \(id)")
print("InApp URL: \(String(describing: url))")
print("InApp Payload: \(payload)")
}

//https://developers.mindbox.ru/docs/in-app
// https://developers.mindbox.ru/docs/in-app
func inAppMessageDismissed(id: String) {
//Here you can add your custom logic
print("inAppMessageDismissed")
print(id)
print("InApp ID: \(id)")
}

func select(chooseInappMessageDelegate: ChooseInappMessageDelegate) {
Expand Down
6 changes: 3 additions & 3 deletions Example/Example/ViewModels/MainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Observation
var deviceUUID: String = ""
var APNSToken: String = ""

//https://developers.mindbox.ru/docs/ios-sdk-methods
// https://developers.mindbox.ru/docs/ios-sdk-methods
func setupData() {
self.SDKVersion = Mindbox.shared.sdkVersion
Mindbox.shared.getDeviceUUID { deviceUUID in
Expand All @@ -32,7 +32,7 @@ import Observation
ChooseInAppMessagesDelegate.shared.select(chooseInappMessageDelegate: .InAppMessagesDelegate)
}

//https://developers.mindbox.ru/docs/in-app-targeting-by-custom-operation
// https://developers.mindbox.ru/docs/in-app-targeting-by-custom-operation
func showInAppWithExecuteSyncOperation () {
let json = """
{ "viewProduct":
Expand All @@ -53,7 +53,7 @@ import Observation
}
}

//https://developers.mindbox.ru/docs/in-app-targeting-by-custom-operation
// https://developers.mindbox.ru/docs/in-app-targeting-by-custom-operation
func showInAppWithExecuteAsyncOperation () {
let json = """
{ "viewProduct":
Expand Down
Loading

0 comments on commit 3789f5d

Please sign in to comment.