Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Example/.gitignore

This file was deleted.

474 changes: 139 additions & 335 deletions Example/Example.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions Example/Example.xcworkspace/contents.xcworkspacedata

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class AppDelegate: MindboxAppDelegate {
return true
}

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

// https://developers.mindbox.ru/docs/ios-sdk-handle-tap
// https://developers.mindbox.ru/docs/ios-push-notification-deep-linking
override func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
Expand All @@ -66,7 +66,7 @@ final 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-quick-setup-push-notifications
func registerForRemoteNotifications() {
UNUserNotificationCenter.current().delegate = self
DispatchQueue.main.async {
Expand Down
14 changes: 0 additions & 14 deletions Example/Example/Models/Payload.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@

import SwiftUI
import SwiftData
import Mindbox

struct NotificationCenterView: View {

var viewModel: NotificationCenterViewModelProtocol

@State private var showAlert = false
@State private var alertTitle = String()
@State private var alertMessage = String()

@Environment(\.modelContext) private var modelContext
@Query private var items: [Item]

var body: some View {
NavigationStack {
List {
Expand All @@ -31,7 +32,7 @@ struct NotificationCenterView: View {
Spacer()
}
}

.contentShape(Rectangle())
.onTapGesture {
viewModel.sendOperationNCPushOpen(notification: item.mbPushNotification)
Expand Down Expand Up @@ -60,7 +61,7 @@ struct NotificationCenterView: View {
Button("OK", action: {})
}
}

private func deleteItems(offsets: IndexSet) {
withAnimation {
let originalOffsets = IndexSet(offsets.map { items.count - 1 - $0 })
Expand All @@ -70,14 +71,47 @@ struct NotificationCenterView: View {
return
} else {
modelContext.delete(items[index])

}
}
}
UIImpactFeedbackGenerator(style: .heavy).impactOccurred()
}
}

// MARK: - NotificationCellView

private struct NotificationCellView: View {
var notification: PushNotification

var body: some View {
HStack(alignment: .center, content: {
if let imageUrl = notification.imageUrl, let url = URL(string: imageUrl) {
AsyncImage(url: url) { image in
image
.resizable()
.scaledToFill()
} placeholder: {
ProgressView()
}
.frame(maxWidth: 64, maxHeight: 64)
.clipShape(Circle())
}

VStack(alignment: .leading, content: {
Text(notification.title ?? "Empty")
.font(.headline)
Text(notification.body ?? "Empty")
.font(.subheadline)
.foregroundStyle(.gray)
Text(notification.clickUrl ?? "Empty")
.font(.footnote)
.foregroundStyle(.blue)
})
})
}
}

#Preview {
NotificationCenterView(viewModel: NotificationCenterViewModel())
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Item+SwiftData.swift
// NotificationModels.swift
// Example
//
// Created by Sergei Semko on 6/11/24.
Expand All @@ -13,7 +13,7 @@ import SwiftData
public final class Item {
public var timestamp: Date
public var mbPushNotification: PushNotification

public init(timestamp: Date, pushNotification: PushNotification) {
self.timestamp = timestamp
self.mbPushNotification = pushNotification
Expand All @@ -27,9 +27,14 @@ public struct PushNotification: Codable {
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)
}
}

public struct Payload: Codable {
var pushName: String
var pushDate: String
}

This file was deleted.

13 changes: 0 additions & 13 deletions Example/Podfile

This file was deleted.

72 changes: 27 additions & 45 deletions Example/README.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,47 @@
# Example app with SPM for Mindbox SDK for iOS
# Example app for Mindbox SDK for iOS

This is an example of SDK [integration](https://developers.mindbox.ru/docs/ios-sdk-integration)
This is an example of SDK [integration](https://developers.mindbox.ru/docs/ios-sdk).

## Getting started

### Launching the application
The app has integration via cocoapods, but you can use SPM if you need.
#### Cocoapods:

The app uses SPM to integrate the Mindbox SDK. Xcode will resolve and download the dependency when you open the project.

1. [Clone ios-sdk repository](https://github.com/mindbox-cloud/ios-sdk).
2. Make sure you have CocoaPods installed or install it according to the instructions.
3. Go to `ios-sdk/Example/`
4. Install the pods.
```ruby
pod update
```
Or
```ruby
pod install
```
5. Go to `ios-sdk/Example/Example.xcworkspace`.
6. Run file `Example.xcworkspace`.
#### SPM:
1. To deintegrate cocoapods you can use next comands:
- `sudo gem install cocoapods-deintegrate`
- `pod deintegrate`
- `rm Podfile`
- `rm Podfile.lock`
- `rm Example.xcworkspace`
- `rm -rf Pods`
2. Launch `Example.xcodeproj`.
3. [Read this](https://developers.mindbox.ru/docs/add-ios-sdk) and follow the initialization instructions via SPM.
2. Open `ios-sdk/Example/Example.xcodeproj`.
3. To ensure you have the latest SDK version: **File → Packages → Update to Latest Package Versions**.
4. Build and run.

Now you can test the in-app on the simulator.
In our admin panel there are already 3 ready-made in-apps that you can look at.
Now you can test the in-app on the simulator.
In our admin panel there are already 3 ready-made in-apps that you can look at.
To run the application on a real device and try push notifications, follow the instructions below.

### Setting up a Example application with your personal account (to run on a real device)
### Setting up the Example application with your personal account (to run on a real device)

1. Change [team](https://developers.mindbox.ru/docs/ios-get-keys) and bundle identifiers and App Group name for next targets:
- ExampleApp
- MindboxNotificationServiceExtension
- MindboxNotificationContentExtension
- ExampleApp
- MindboxNotificationServiceExtension
- MindboxNotificationContentExtension
2. [Configure your endpoints](https://developers.mindbox.ru/docs/add-ios-integration).
3. Change domain and endpoints in the `AppDelegate.swift` to yours.

### SDK functionality testing

1. To check innap when opening:
- [Read this](https://help.mindbox.ru/docs/in-app-what-is).
- Open app.
2. To check the inapp anywhere in the application:
- [Read this](https://help.mindbox.ru/docs/in-app-location).
- Replace `operationSystemName` in `showInAppWithExecuteSyncOperation` and `showInAppWithExecuteAsyncOperation` in MainViewModel.
- Click to the button `Show in-app` opposite the selected operation.
1. To check in-app when opening:
- [Read this](https://help.mindbox.ru/docs/in-apps).
- Open app.
2. To check the in-app anywhere in the application:
- [Read this](https://help.mindbox.ru/docs/in-app-location).
- Replace `operationSystemName` in `showInAppWithExecuteSyncOperation` and `showInAppWithExecuteAsyncOperation` in MainViewModel.
- Click to the button `Show in-app` opposite the selected operation.
3. To check push notifications:
- [Read this](https://developers.mindbox.ru/docs/ios-send-push-notifications-advanced)
- Send a notification from your account.
- [Read this](https://developers.mindbox.ru/docs/mobile-push-check)
- Send a notification from your account.
4. To check rich notifications:
- [Read this](https://developers.mindbox.ru/docs/ios-send-push-notifications-advanced)
- Send a notification from your account.
- [Read this](https://developers.mindbox.ru/docs/mobile-push-check)
- Send a notification from your account.

### Additionally
- Currently the In-App only comes once per session.
- There are comments and links in the ExampleApp code that can help you.
- Currently the In-App only comes once per session.
- There are comments and links in the ExampleApp code that can help you.
Loading