Skip to content

Commit 00a19cb

Browse files
rleojosephpierremichel.villa
andauthored
[MINI-6142] Access token hot fix (#521)
* Hotfix release changes * Swiftlint fix * Swiftlint * Swiftlint * Update Sources/Classes/core/View/MiniAppView.swift Co-authored-by: pierremichel.villa <[email protected]> --------- Co-authored-by: pierremichel.villa <[email protected]>
1 parent 02a2385 commit 00a19cb

File tree

10 files changed

+93
-10
lines changed

10 files changed

+93
-10
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
## CHANGELOG
22

3+
### 5.3.1 (2023-08-01)
4+
**SDK**
5+
- **Feature:** Updated `loadFromBundle(miniAppManifest:completionHandler)` interface with optional MiniAppManifest object.
6+
- **Feature:** Added a new property in MiniAppViewable class to Enable/Disable 3D touch for the Miniapp that is launched.
7+
8+
**Sample App**
9+
- **Feature:** Updated Sample app to send `miniAppManifest` while loading from bundle
10+
- **Feature:** Hardcoded permissions for `loadFromBundle` approach
11+
---
12+
313
### 5.3.0 (2023-07-25)
414
**SDK**
515
- **Deprecated:** `create(appInfo: ,queryParams: ,completionHandler: ,messageInterface: ,adsDisplayer: ,fromCache: ) in `MiniApp` class.

Example/Controllers/SwiftUI/Features/Bundle/MiniAppFromBundle.swift

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@ struct MiniAppFromBundle: View {
55

66
@State var isMiniAppLoading: Bool = false
77

8+
init() {
9+
MiniApp.shared(with: ListConfiguration(listType: .listI).sdkConfig).setCustomPermissions(forMiniApp: "mini-app-testing-appid", permissionList: permissionList())
10+
}
811
var body: some View {
912
VStack {
10-
MiniAppSUIView(params: miniAppViewParams(config: ListConfiguration(listType: .listI).sdkConfig), fromCache: true, handler: MiniAppSUIViewHandler(), fromBundle: true)
13+
MiniAppSUIView(params: miniAppViewParams(config: ListConfiguration(listType: .listI).sdkConfig),
14+
fromCache: true,
15+
handler: MiniAppSUIViewHandler(),
16+
fromBundle: true,
17+
miniAppManifest: getMiniAppManifest())
1118
}
1219
.navigationTitle("MiniApp")
1320
}
@@ -26,4 +33,38 @@ struct MiniAppFromBundle: View {
2633
queryParams: getQueryParam()
2734
)
2835
}
36+
37+
func getMiniAppManifest() -> MiniAppManifest? {
38+
return MiniAppManifest(requiredPermissions: permissionList(),
39+
optionalPermissions: nil,
40+
customMetaData: nil,
41+
accessTokenPermissions: [MASDKAccessTokenScopes(audience: "rae",
42+
scopes: ["idinfo_read_openid", "memberinfo_read_point"])!],
43+
versionId: "")
44+
}
45+
46+
private func permissionList() -> [MASDKCustomPermissionModel] {
47+
do {
48+
let permissions: [MiniAppCustomPermissionType] = [.userName, .profilePhoto, .contactsList, .fileDownload, .accessToken, .deviceLocation, .sendMessage, .points]
49+
50+
return try permissions.map { try MASDKCustomPermissionModel.customPermissionModel(permissionName: $0) }
51+
} catch {
52+
print("Failed to set up MiniApp permissions")
53+
return []
54+
}
55+
}
56+
}
57+
58+
extension MASDKCustomPermissionModel {
59+
static func customPermissionModel(permissionName: MiniAppCustomPermissionType, isPermissionGranted: MiniAppCustomPermissionGrantedStatus = .allowed, permissionRequestDescription: String? = "") throws -> Self {
60+
let data = [
61+
"permissionName": permissionName.rawValue,
62+
"isPermissionGranted": isPermissionGranted.rawValue,
63+
"permissionDescription": permissionRequestDescription
64+
]
65+
66+
let encodedData = try JSONEncoder().encode(data)
67+
68+
return try JSONDecoder().decode(Self.self, from: encodedData)
69+
}
2970
}

MiniApp.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |miniapp|
22
miniapp.name = 'MiniApp'
3-
miniapp.version = '5.3.0'
3+
miniapp.version = '5.3.1'
44
miniapp.authors = "Rakuten Ecosystem Mobile"
55
miniapp.summary = "Rakuten's Mini App SDK"
66
miniapp.description = "This open-source library allows you to integrate Mini App ecosystem into your iOS applications. Mini App SDK also facilitates communication between a mini app and the host app via a message bridge."

Sources/Classes/core/MiniApp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import UIKit
33

44
/// Mini App Public API methods
55
public class MiniApp: NSObject {
6-
public static let version = "5.3.0"
6+
public static let version = "5.3.1"
77
private static let shared = MiniApp()
88
private let realMiniApp = RealMiniApp()
99
public static var MAOrientationLock: UIInterfaceOrientationMask = []

Sources/Classes/core/View/MiniAppView.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ public class MiniAppView: UIView, MiniAppViewable {
3535
}
3636
var cancellables = Set<AnyCancellable>()
3737

38+
fileprivate var enableLinkPreview: Bool = true
39+
40+
public var enable3DTouch: Bool {
41+
get {
42+
return enableLinkPreview
43+
}
44+
set {
45+
enableLinkPreview = newValue
46+
}
47+
}
48+
3849
public init(params: MiniAppViewParameters) {
3950
switch params {
4051
case let .default(params):
@@ -98,6 +109,7 @@ public class MiniAppView: UIView, MiniAppViewable {
98109

99110
internal func setupWebView(webView: MiniAppWebView) {
100111
self.webView = webView
112+
self.webView?.allowsLinkPreview = enableLinkPreview
101113
webView.translatesAutoresizingMaskIntoConstraints = false
102114
self.addSubview(webView)
103115
NSLayoutConstraint.activate([
@@ -163,13 +175,13 @@ public class MiniAppView: UIView, MiniAppViewable {
163175
}
164176
}
165177

166-
public func loadFromBundle(completion: @escaping ((Result<Bool, MASDKError>) -> Void)) {
178+
public func loadFromBundle(miniAppManifest: MiniAppManifest?, completion: @escaping ((Result<Bool, MASDKError>) -> Void)) {
167179
guard webView == nil else {
168180
completion(.failure(miniAppAlreadyLoadedError))
169181
return
170182
}
171183
state.send(.loading)
172-
miniAppHandler.loadFromBundle { [weak self] result in
184+
miniAppHandler.loadFromBundle(miniAppManifest: miniAppManifest) { [weak self] result in
173185
switch result {
174186
case let .success(webView):
175187
self?.state.send(.active)

Sources/Classes/core/View/MiniAppViewHandler.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,12 @@ class MiniAppViewHandler: NSObject {
292292
}
293293
}
294294

295-
func loadFromBundle(completion: @escaping ((Result<MiniAppWebView, MASDKError>) -> Void)) {
295+
func loadFromBundle(miniAppManifest: MiniAppManifest? = nil, completion: @escaping ((Result<MiniAppWebView, MASDKError>) -> Void)) {
296296
guard let versionId = version else {
297297
completion(.failure(.invalidVersionId))
298298
return
299299
}
300+
saveManifestInfoForBundle(miniAppManifest: miniAppManifest)
300301
if isValidMiniAppInfo(versionId: versionId) {
301302
if isMiniAppAvailable(versionId: versionId) {
302303
if miniAppDownloader.isCacheSecure(appId: appId, versionId: versionId) {
@@ -328,6 +329,13 @@ class MiniAppViewHandler: NSObject {
328329
}
329330
}
330331

332+
func saveManifestInfoForBundle(miniAppManifest: MiniAppManifest?) {
333+
guard let manifest = miniAppManifest else {
334+
return
335+
}
336+
miniAppManifestStorage.saveManifestInfo(forMiniApp: appId, manifest: manifest)
337+
}
338+
331339
func loadWebView(
332340
webView: MiniAppWebView,
333341
miniAppTitle: String = "MiniApp",

Sources/Classes/core/View/MiniAppViewable.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ public protocol MiniAppViewable: UIView, MiniAppNavigationBarDelegate {
3333
///
3434
var alertInfo: CloseAlertInfo? { get }
3535

36+
var enable3DTouch: Bool { get }
37+
38+
func loadFromBundle(miniAppManifest: MiniAppManifest?, completion: @escaping ((Result<Bool, MASDKError>) -> Void))
3639
}
3740

3841
public extension MiniAppViewable {
@@ -44,4 +47,8 @@ public extension MiniAppViewable {
4447
func loadAsync(fromCache: Bool = false) async throws -> MiniAppView.MiniAppLoadStatus {
4548
try await loadAsync(fromCache: fromCache)
4649
}
50+
51+
func loadFromBundle(miniAppManifest: MiniAppManifest? = nil, completion: @escaping ((Result<Bool, MASDKError>) -> Void)) {
52+
loadFromBundle(miniAppManifest: miniAppManifest, completion: completion)
53+
}
4754
}

Sources/Classes/ui/MiniAppSUIView.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ public struct MiniAppSUIView: UIViewRepresentable {
1111
var fromCache: Bool = false
1212
var fromBundle: Bool = false
1313

14-
public init(params: MiniAppViewParameters.DefaultParams, fromCache: Bool = false, handler: MiniAppSUIViewHandler, fromBundle: Bool = false) {
14+
// This parameter will be used for loadFromBundle only
15+
var miniAppManifest: MiniAppManifest?
16+
17+
public init(params: MiniAppViewParameters.DefaultParams, fromCache: Bool = false, handler: MiniAppSUIViewHandler, fromBundle: Bool = false, miniAppManifest: MiniAppManifest? = nil) {
1518
self.params = .default(params)
1619
self.fromCache = fromCache
1720
self.handler = handler
1821
self.fromBundle = fromBundle
22+
self.miniAppManifest = miniAppManifest
1923
}
2024

2125
public init(urlParams: MiniAppViewParameters.UrlParams) {
@@ -33,7 +37,8 @@ public struct MiniAppSUIView: UIViewRepresentable {
3337
let view = MiniAppView(params: params)
3438
view.progressStateView = MiniAppProgressView()
3539
if fromBundle {
36-
view.loadFromBundle {_ in
40+
view.enable3DTouch = false
41+
view.loadFromBundle(miniAppManifest: miniAppManifest) {_ in
3742
self.handler.isActive = true
3843
}
3944
} else {

Tests/Unit/MiniAppScriptMessageHandlerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ class MiniAppScriptMessageHandlerTests: QuickSpec {
11061106
return
11071107
}
11081108
let environmentInfo = ResponseDecoder.decode(decodeType: MAHostEnvironmentInfo.self, data: responseData)
1109-
expect(environmentInfo?.sdkVersion).toEventually(equal("5.3.0"))
1109+
expect(environmentInfo?.sdkVersion).toEventually(equal("5.3.1"))
11101110
expect(environmentInfo?.hostVersion).toEventually(equal(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String))
11111111
expect(environmentInfo?.hostLocale).toEventually(equal("en-US"))
11121112
}

USERGUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ To integrate MiniApp SDK into your Xcode project using Swift Package Manager, ad
8383

8484
```ruby
8585
dependencies: [
86-
.package(url: "https://github.com/rakutentech/ios-miniapp.git", .upToNextMajor(from: "5.3.0"))
86+
.package(url: "https://github.com/rakutentech/ios-miniapp.git", .upToNextMajor(from: "5.3.1"))
8787
]
8888
```
8989

0 commit comments

Comments
 (0)