Skip to content

Commit

Permalink
Merge pull request #448 from mindbox-cloud/release/2.11.1
Browse files Browse the repository at this point in the history
Release/2.11.1
  • Loading branch information
AndreyEmtsov authored Oct 7, 2024
2 parents d5b1433 + c701f16 commit a9e2f4d
Show file tree
Hide file tree
Showing 90 changed files with 6,645 additions and 360 deletions.
18 changes: 0 additions & 18 deletions Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,9 @@
474F37A42C16F5B000F38BB0 /* NotificationCenterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 474F37A32C16F5B000F38BB0 /* NotificationCenterView.swift */; };
474F37AE2C170FB600F38BB0 /* NotificationCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 474F37AD2C170FB600F38BB0 /* NotificationCellView.swift */; };
4774807A2C174BAA00580FB2 /* Payload.swift in Sources */ = {isa = PBXBuildFile; fileRef = 477480792C174BAA00580FB2 /* Payload.swift */; };
4774807F2C174C2000580FB2 /* MBPushNotification+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4774807E2C174C2000580FB2 /* MBPushNotification+Extensions.swift */; };
47D63E2D2C2EAD220055E7D8 /* Mindbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 47D63E2C2C2EAD220055E7D8 /* Mindbox.framework */; };
47FFE2232C187B650007E2F6 /* Item+SwiftData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 472423982C185B8400B2A9BC /* Item+SwiftData.swift */; };
47FFE2262C187D3C0007E2F6 /* SwiftDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47FFE2252C187D3C0007E2F6 /* SwiftDataManager.swift */; };
47FFE2282C187D5C0007E2F6 /* SwiftDataManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47FFE2252C187D3C0007E2F6 /* SwiftDataManager.swift */; };
47FFE22A2C1885A90007E2F6 /* MBPushNotification+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4774807E2C174C2000580FB2 /* MBPushNotification+Extensions.swift */; };
47FFE22C2C1886550007E2F6 /* Payload.swift in Sources */ = {isa = PBXBuildFile; fileRef = 477480792C174BAA00580FB2 /* Payload.swift */; };
9E3108F96D4F26745D3B37A4 /* Pods_MindboxNotificationServiceExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4AF2BFD8ABA97C73F589C5DB /* Pods_MindboxNotificationServiceExtension.framework */; };
D9585975AC05213E1682C760 /* Pods_MindboxNotificationContentExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 91EB2315545CE887D05CB505 /* Pods_MindboxNotificationContentExtension.framework */; };
Expand Down Expand Up @@ -102,7 +99,6 @@
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>"; };
4774807E2C174C2000580FB2 /* MBPushNotification+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MBPushNotification+Extensions.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 All @@ -120,7 +116,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
47D63E2D2C2EAD220055E7D8 /* Mindbox.framework in Frameworks */,
9E3108F96D4F26745D3B37A4 /* Pods_MindboxNotificationServiceExtension.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -202,7 +197,6 @@
474F37AF2C1710BB00F38BB0 /* Models */,
0AEDBC9D2BB71FC600EE8722 /* Views */,
0AEDBC9E2BB71FD700EE8722 /* ViewModels */,
4774807B2C174BD900580FB2 /* Extensions */,
);
path = Example;
sourceTree = "<group>";
Expand Down Expand Up @@ -254,14 +248,6 @@
path = Models;
sourceTree = "<group>";
};
4774807B2C174BD900580FB2 /* Extensions */ = {
isa = PBXGroup;
children = (
4774807E2C174C2000580FB2 /* MBPushNotification+Extensions.swift */,
);
path = Extensions;
sourceTree = "<group>";
};
477480842C1760BE00580FB2 /* ChooseInAppMessagesDelegate */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -529,7 +515,6 @@
47FFE2232C187B650007E2F6 /* Item+SwiftData.swift in Sources */,
0A0DE3482BB8455A00812E73 /* NotificationService.swift in Sources */,
47FFE22C2C1886550007E2F6 /* Payload.swift in Sources */,
47FFE22A2C1885A90007E2F6 /* MBPushNotification+Extensions.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -558,7 +543,6 @@
0AEDBC7C2BB6F8F200EE8722 /* SceneDelegate.swift in Sources */,
0AEDBC9B2BB70D6E00EE8722 /* SDKDataView.swift in Sources */,
0A4B681A2BBC82B500639BC5 /* ChooseInAppMessagesDelegate.swift in Sources */,
4774807F2C174C2000580FB2 /* MBPushNotification+Extensions.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -590,7 +574,6 @@
"$(inherited)",
"\"${PODS_CONFIGURATION_BUILD_DIR}/MindboxLogger\"",
"\"${PODS_CONFIGURATION_BUILD_DIR}/MindboxNotifications\"",
"\"${PODS_CONFIGURATION_BUILD_DIR}/Mindbox\"",
);
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = MindboxNotificationServiceExtension/Info.plist;
Expand Down Expand Up @@ -624,7 +607,6 @@
"$(inherited)",
"\"${PODS_CONFIGURATION_BUILD_DIR}/MindboxLogger\"",
"\"${PODS_CONFIGURATION_BUILD_DIR}/MindboxNotifications\"",
"\"${PODS_CONFIGURATION_BUILD_DIR}/Mindbox\"",
);
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = MindboxNotificationServiceExtension/Info.plist;
Expand Down
31 changes: 0 additions & 31 deletions Example/Example/Extensions/MBPushNotification+Extensions.swift

This file was deleted.

19 changes: 16 additions & 3 deletions Example/Example/Models/Item+SwiftData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,29 @@
//

import Foundation
import Mindbox
import SwiftData

@Model
public final class Item {
public var timestamp: Date
public var mbPushNotification: MBPushNotification
public var mbPushNotification: PushNotification

public init(timestamp: Date, pushNotification: MBPushNotification) {
public init(timestamp: Date, pushNotification: PushNotification) {
self.timestamp = timestamp
self.mbPushNotification = pushNotification
}
}

public struct PushNotification: Codable {
public let title: String?
public let body: String?
public let clickUrl: String?
public let imageUrl: String?
public let payload: String?
public let uniqueKey: String?

var decodedPayload: Payload? {
guard let payloadData = payload?.data(using: .utf8) else { return nil }
return try? JSONDecoder().decode(Payload.self, from: payloadData)
}
}
89 changes: 27 additions & 62 deletions Example/Example/Services/SwiftDataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import Mindbox
import SwiftData
import SwiftUI

Expand Down Expand Up @@ -48,12 +47,8 @@ public struct SwiftDataManager {
private func saveMockData() {
let context = SwiftDataManager.shared.container.mainContext

testNotifications.forEach { notification in
guard let pushNotification = MBPushNotification(jsonString: notification) else {
print("Failed to create MBPushNotification")
return
}
let newItem = Item(timestamp: Date(), pushNotification: pushNotification)
mockNotifications.forEach { notification in
let newItem = Item(timestamp: Date(), pushNotification: notification)

context.insert(newItem)

Expand All @@ -67,64 +62,34 @@ public struct SwiftDataManager {
}

private extension SwiftDataManager {
var testNotifications: [String] {
var mockNotifications: [PushNotification] {
[
"""
{
"aps": {
"alert": {
"title": "First notification title",
"body": "First notification body"
},
"sound": "default",
"mutable-content": 1,
"content-available": 1
},
"uniqueKey": "Push unique key: 1",
"imageUrl": "https://mobpush-images.mindbox.ru/Mpush-test/1a73ebaa-3e5f-49f4-ae6c-462c9b64d34c/307be696-77e6-4d83-b7eb-c94be85f7a03.png",
"payload": "{\\"pushName\\": \\"<Push name>\\", \\"pushDate\\": \\"<Push date>\\"}",
"buttons": [],
"clickUrl": "https://mindbox.ru/"
}
""",
PushNotification(
title: "First notification title",
body: "First notification body",
clickUrl: "https://mindbox.ru/",
imageUrl: "https://mobpush-images.mindbox.ru/Mpush-test/1a73ebaa-3e5f-49f4-ae6c-462c9b64d34c/307be696-77e6-4d83-b7eb-c94be85f7a03.png",
payload: "{\"pushName\": \"<Push name>\", \"pushDate\": \"<Push date>\"}",
uniqueKey: "Push unique key: 1"
),

"""
{
"aps": {
"alert": {
"title": "Second notification title",
"body": "Second notification body"
},
"sound": "default",
"mutable-content": 1,
"content-available": 1
},
"uniqueKey": "Push unique key: 2",
"imageUrl": "https://mobpush-images.mindbox.ru/Mpush-test/1a73ebaa-3e5f-49f4-ae6c-462c9b64d34c/2397fea9-383d-49bf-a6a0-181a267faa94.png",
"payload": "{\\"pushName\\": \\"<Push name>\\", \\"pushDate\\": \\"<Push date>\\"}",
"buttons": [],
"clickUrl": "https://mindbox.ru/"
}
""",
PushNotification(
title: "Second notification title",
body: "Second notification body",
clickUrl: "https://mindbox.ru/",
imageUrl: "https://mobpush-images.mindbox.ru/Mpush-test/1a73ebaa-3e5f-49f4-ae6c-462c9b64d34c/2397fea9-383d-49bf-a6a0-181a267faa94.png",
payload: "{\"pushName\": \"<Push name>\", \"pushDate\": \"<Push date>\"}",
uniqueKey: "Push unique key: 2"
),

"""
{
"aps": {
"alert": {
"title": "Third notification title",
"body": "Third notification body"
},
"sound": "default",
"mutable-content": 1,
"content-available": 1
},
"uniqueKey": "Push unique key: 3",
"imageUrl": "https://mobpush-images.mindbox.ru/Mpush-test/1a73ebaa-3e5f-49f4-ae6c-462c9b64d34c/bd4250b1-a7ac-4b8a-b91b-481b3b5c565c.png",
"payload": "{\\"pushName\\": \\"<Push name>\\", \\"pushDate\\": \\"<Push date>\\"}",
"buttons": [],
"clickUrl": "https://mindbox.ru/"
}
"""
PushNotification(
title: "Third notification title",
body: "Third notification body",
clickUrl: "https://mindbox.ru/",
imageUrl: "https://mobpush-images.mindbox.ru/Mpush-test/1a73ebaa-3e5f-49f4-ae6c-462c9b64d34c/bd4250b1-a7ac-4b8a-b91b-481b3b5c565c.png",
payload: "{\"pushName\": \"<Push name>\", \"pushDate\": \"<Push date>\"}",
uniqueKey: "Push unique key: 3"
),
]
}
}
8 changes: 4 additions & 4 deletions Example/Example/ViewModels/NotificationCenterViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import Mindbox
import Observation

protocol NotificationCenterViewModelProtocol: AnyObject {
var lastTappedNotification: MBPushNotification? { get }
var lastTappedNotification: PushNotification? { get }
var errorMessage: String? { get }

func sendOperationNCPushOpen(notification: MBPushNotification)
func sendOperationNCPushOpen(notification: PushNotification)
func sendOperationNCOpen()
}

@Observable final class NotificationCenterViewModel: NotificationCenterViewModelProtocol {

// MARK: - NotificationCenterViewModelProtocol
var errorMessage: String?
var lastTappedNotification: MBPushNotification?
var lastTappedNotification: PushNotification?

func sendOperationNCPushOpen(notification: MBPushNotification) {
func sendOperationNCPushOpen(notification: PushNotification) {
lastTappedNotification = notification

/*Assuming payload of push notification has this structure:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI
import Mindbox

struct NotificationCellView: View {
var notification: MBPushNotification
var notification: PushNotification

var body: some View {
HStack(alignment: .center, content: {
Expand All @@ -27,9 +27,9 @@ struct NotificationCellView: View {
}

VStack(alignment: .leading, content: {
Text(notification.aps?.alert?.title ?? "Empty")
Text(notification.title ?? "Empty")
.font(.headline)
Text(notification.aps?.alert?.body ?? "Empty")
Text(notification.body ?? "Empty")
.font(.subheadline)
.foregroundStyle(.gray)
Text(notification.clickUrl ?? "Empty")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

import UserNotifications
import MindboxNotifications
import Mindbox

class NotificationService: UNNotificationServiceExtension {

lazy var mindboxService = MindboxNotificationService()

override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
let userInfo = request.content.userInfo

if let mindboxPushNotification = Mindbox.shared.getMindboxPushData(userInfo: request.content.userInfo) {
if mindboxService.isMindboxPush(userInfo: userInfo), let mindboxPushNotification = mindboxService.getMindboxPushData(userInfo: userInfo) {
Task {
await saveSwiftDataItem(mindboxPushNotification)
}
Expand All @@ -32,10 +32,16 @@ class NotificationService: UNNotificationServiceExtension {
}

@MainActor
private func saveSwiftDataItem(_ pushNotification: MBPushNotification) async {
private func saveSwiftDataItem(_ mindboxPushNotification: MBPushNotification) async {
let context = SwiftDataManager.shared.container.mainContext

let newItem = Item(timestamp: Date(), pushNotification: pushNotification)
let push = PushNotification(title: mindboxPushNotification.aps?.alert?.title,
body: mindboxPushNotification.aps?.alert?.body,
clickUrl: mindboxPushNotification.clickUrl,
imageUrl: mindboxPushNotification.imageUrl,
payload: mindboxPushNotification.payload,
uniqueKey: mindboxPushNotification.uniqueKey)
let newItem = Item(timestamp: Date(), pushNotification: push)

context.insert(newItem)
do {
Expand Down
6 changes: 3 additions & 3 deletions Example/Podfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use_frameworks!

target 'Example' do
pod 'Mindbox', '2.11.0'
pod 'Mindbox', '2.11.1'
end

target 'MindboxNotificationServiceExtension' do
pod 'MindboxNotifications', '2.11.0'
pod 'MindboxNotifications', '2.11.1'
end

target 'MindboxNotificationContentExtension' do
pod 'MindboxNotifications', '2.11.0'
pod 'MindboxNotifications', '2.11.1'
end
Loading

0 comments on commit a9e2f4d

Please sign in to comment.