From 00a19cba16d253c5622af16e12587cd00dec1d9b Mon Sep 17 00:00:00 2001 From: "leojoseph.r" <58416454+rleojoseph@users.noreply.github.com> Date: Tue, 1 Aug 2023 12:25:17 +0900 Subject: [PATCH 1/4] [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 --------- Co-authored-by: pierremichel.villa --- CHANGELOG.md | 10 +++++ .../Features/Bundle/MiniAppFromBundle.swift | 43 ++++++++++++++++++- MiniApp.podspec | 2 +- Sources/Classes/core/MiniApp.swift | 2 +- Sources/Classes/core/View/MiniAppView.swift | 16 ++++++- .../core/View/MiniAppViewHandler.swift | 10 ++++- .../Classes/core/View/MiniAppViewable.swift | 7 +++ Sources/Classes/ui/MiniAppSUIView.swift | 9 +++- .../MiniAppScriptMessageHandlerTests.swift | 2 +- USERGUIDE.md | 2 +- 10 files changed, 93 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f3e06f31..21881548 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ ## CHANGELOG +### 5.3.1 (2023-08-01) +**SDK** +- **Feature:** Updated `loadFromBundle(miniAppManifest:completionHandler)` interface with optional MiniAppManifest object. +- **Feature:** Added a new property in MiniAppViewable class to Enable/Disable 3D touch for the Miniapp that is launched. + +**Sample App** +- **Feature:** Updated Sample app to send `miniAppManifest` while loading from bundle +- **Feature:** Hardcoded permissions for `loadFromBundle` approach +--- + ### 5.3.0 (2023-07-25) **SDK** - **Deprecated:** `create(appInfo: ,queryParams: ,completionHandler: ,messageInterface: ,adsDisplayer: ,fromCache: ) in `MiniApp` class. diff --git a/Example/Controllers/SwiftUI/Features/Bundle/MiniAppFromBundle.swift b/Example/Controllers/SwiftUI/Features/Bundle/MiniAppFromBundle.swift index b1d9a1c1..e429f6d6 100644 --- a/Example/Controllers/SwiftUI/Features/Bundle/MiniAppFromBundle.swift +++ b/Example/Controllers/SwiftUI/Features/Bundle/MiniAppFromBundle.swift @@ -5,9 +5,16 @@ struct MiniAppFromBundle: View { @State var isMiniAppLoading: Bool = false + init() { + MiniApp.shared(with: ListConfiguration(listType: .listI).sdkConfig).setCustomPermissions(forMiniApp: "mini-app-testing-appid", permissionList: permissionList()) + } var body: some View { VStack { - MiniAppSUIView(params: miniAppViewParams(config: ListConfiguration(listType: .listI).sdkConfig), fromCache: true, handler: MiniAppSUIViewHandler(), fromBundle: true) + MiniAppSUIView(params: miniAppViewParams(config: ListConfiguration(listType: .listI).sdkConfig), + fromCache: true, + handler: MiniAppSUIViewHandler(), + fromBundle: true, + miniAppManifest: getMiniAppManifest()) } .navigationTitle("MiniApp") } @@ -26,4 +33,38 @@ struct MiniAppFromBundle: View { queryParams: getQueryParam() ) } + + func getMiniAppManifest() -> MiniAppManifest? { + return MiniAppManifest(requiredPermissions: permissionList(), + optionalPermissions: nil, + customMetaData: nil, + accessTokenPermissions: [MASDKAccessTokenScopes(audience: "rae", + scopes: ["idinfo_read_openid", "memberinfo_read_point"])!], + versionId: "") + } + + private func permissionList() -> [MASDKCustomPermissionModel] { + do { + let permissions: [MiniAppCustomPermissionType] = [.userName, .profilePhoto, .contactsList, .fileDownload, .accessToken, .deviceLocation, .sendMessage, .points] + + return try permissions.map { try MASDKCustomPermissionModel.customPermissionModel(permissionName: $0) } + } catch { + print("Failed to set up MiniApp permissions") + return [] + } + } +} + +extension MASDKCustomPermissionModel { + static func customPermissionModel(permissionName: MiniAppCustomPermissionType, isPermissionGranted: MiniAppCustomPermissionGrantedStatus = .allowed, permissionRequestDescription: String? = "") throws -> Self { + let data = [ + "permissionName": permissionName.rawValue, + "isPermissionGranted": isPermissionGranted.rawValue, + "permissionDescription": permissionRequestDescription + ] + + let encodedData = try JSONEncoder().encode(data) + + return try JSONDecoder().decode(Self.self, from: encodedData) + } } diff --git a/MiniApp.podspec b/MiniApp.podspec index cd1d5cf4..45880e1d 100644 --- a/MiniApp.podspec +++ b/MiniApp.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |miniapp| miniapp.name = 'MiniApp' - miniapp.version = '5.3.0' + miniapp.version = '5.3.1' miniapp.authors = "Rakuten Ecosystem Mobile" miniapp.summary = "Rakuten's Mini App SDK" 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." diff --git a/Sources/Classes/core/MiniApp.swift b/Sources/Classes/core/MiniApp.swift index 6e4c168f..817de5da 100644 --- a/Sources/Classes/core/MiniApp.swift +++ b/Sources/Classes/core/MiniApp.swift @@ -3,7 +3,7 @@ import UIKit /// Mini App Public API methods public class MiniApp: NSObject { - public static let version = "5.3.0" + public static let version = "5.3.1" private static let shared = MiniApp() private let realMiniApp = RealMiniApp() public static var MAOrientationLock: UIInterfaceOrientationMask = [] diff --git a/Sources/Classes/core/View/MiniAppView.swift b/Sources/Classes/core/View/MiniAppView.swift index 243a2768..ab2af675 100644 --- a/Sources/Classes/core/View/MiniAppView.swift +++ b/Sources/Classes/core/View/MiniAppView.swift @@ -35,6 +35,17 @@ public class MiniAppView: UIView, MiniAppViewable { } var cancellables = Set() + fileprivate var enableLinkPreview: Bool = true + + public var enable3DTouch: Bool { + get { + return enableLinkPreview + } + set { + enableLinkPreview = newValue + } + } + public init(params: MiniAppViewParameters) { switch params { case let .default(params): @@ -98,6 +109,7 @@ public class MiniAppView: UIView, MiniAppViewable { internal func setupWebView(webView: MiniAppWebView) { self.webView = webView + self.webView?.allowsLinkPreview = enableLinkPreview webView.translatesAutoresizingMaskIntoConstraints = false self.addSubview(webView) NSLayoutConstraint.activate([ @@ -163,13 +175,13 @@ public class MiniAppView: UIView, MiniAppViewable { } } - public func loadFromBundle(completion: @escaping ((Result) -> Void)) { + public func loadFromBundle(miniAppManifest: MiniAppManifest?, completion: @escaping ((Result) -> Void)) { guard webView == nil else { completion(.failure(miniAppAlreadyLoadedError)) return } state.send(.loading) - miniAppHandler.loadFromBundle { [weak self] result in + miniAppHandler.loadFromBundle(miniAppManifest: miniAppManifest) { [weak self] result in switch result { case let .success(webView): self?.state.send(.active) diff --git a/Sources/Classes/core/View/MiniAppViewHandler.swift b/Sources/Classes/core/View/MiniAppViewHandler.swift index d05bdf78..7aa5f25f 100644 --- a/Sources/Classes/core/View/MiniAppViewHandler.swift +++ b/Sources/Classes/core/View/MiniAppViewHandler.swift @@ -292,11 +292,12 @@ class MiniAppViewHandler: NSObject { } } - func loadFromBundle(completion: @escaping ((Result) -> Void)) { + func loadFromBundle(miniAppManifest: MiniAppManifest? = nil, completion: @escaping ((Result) -> Void)) { guard let versionId = version else { completion(.failure(.invalidVersionId)) return } + saveManifestInfoForBundle(miniAppManifest: miniAppManifest) if isValidMiniAppInfo(versionId: versionId) { if isMiniAppAvailable(versionId: versionId) { if miniAppDownloader.isCacheSecure(appId: appId, versionId: versionId) { @@ -328,6 +329,13 @@ class MiniAppViewHandler: NSObject { } } + func saveManifestInfoForBundle(miniAppManifest: MiniAppManifest?) { + guard let manifest = miniAppManifest else { + return + } + miniAppManifestStorage.saveManifestInfo(forMiniApp: appId, manifest: manifest) + } + func loadWebView( webView: MiniAppWebView, miniAppTitle: String = "MiniApp", diff --git a/Sources/Classes/core/View/MiniAppViewable.swift b/Sources/Classes/core/View/MiniAppViewable.swift index c30b493a..29c1793c 100644 --- a/Sources/Classes/core/View/MiniAppViewable.swift +++ b/Sources/Classes/core/View/MiniAppViewable.swift @@ -33,6 +33,9 @@ public protocol MiniAppViewable: UIView, MiniAppNavigationBarDelegate { /// var alertInfo: CloseAlertInfo? { get } + var enable3DTouch: Bool { get } + + func loadFromBundle(miniAppManifest: MiniAppManifest?, completion: @escaping ((Result) -> Void)) } public extension MiniAppViewable { @@ -44,4 +47,8 @@ public extension MiniAppViewable { func loadAsync(fromCache: Bool = false) async throws -> MiniAppView.MiniAppLoadStatus { try await loadAsync(fromCache: fromCache) } + + func loadFromBundle(miniAppManifest: MiniAppManifest? = nil, completion: @escaping ((Result) -> Void)) { + loadFromBundle(miniAppManifest: miniAppManifest, completion: completion) + } } diff --git a/Sources/Classes/ui/MiniAppSUIView.swift b/Sources/Classes/ui/MiniAppSUIView.swift index a492d3a2..e67780d3 100644 --- a/Sources/Classes/ui/MiniAppSUIView.swift +++ b/Sources/Classes/ui/MiniAppSUIView.swift @@ -11,11 +11,15 @@ public struct MiniAppSUIView: UIViewRepresentable { var fromCache: Bool = false var fromBundle: Bool = false - public init(params: MiniAppViewParameters.DefaultParams, fromCache: Bool = false, handler: MiniAppSUIViewHandler, fromBundle: Bool = false) { + // This parameter will be used for loadFromBundle only + var miniAppManifest: MiniAppManifest? + + public init(params: MiniAppViewParameters.DefaultParams, fromCache: Bool = false, handler: MiniAppSUIViewHandler, fromBundle: Bool = false, miniAppManifest: MiniAppManifest? = nil) { self.params = .default(params) self.fromCache = fromCache self.handler = handler self.fromBundle = fromBundle + self.miniAppManifest = miniAppManifest } public init(urlParams: MiniAppViewParameters.UrlParams) { @@ -33,7 +37,8 @@ public struct MiniAppSUIView: UIViewRepresentable { let view = MiniAppView(params: params) view.progressStateView = MiniAppProgressView() if fromBundle { - view.loadFromBundle {_ in + view.enable3DTouch = false + view.loadFromBundle(miniAppManifest: miniAppManifest) {_ in self.handler.isActive = true } } else { diff --git a/Tests/Unit/MiniAppScriptMessageHandlerTests.swift b/Tests/Unit/MiniAppScriptMessageHandlerTests.swift index e7f70b94..9e414359 100644 --- a/Tests/Unit/MiniAppScriptMessageHandlerTests.swift +++ b/Tests/Unit/MiniAppScriptMessageHandlerTests.swift @@ -1106,7 +1106,7 @@ class MiniAppScriptMessageHandlerTests: QuickSpec { return } let environmentInfo = ResponseDecoder.decode(decodeType: MAHostEnvironmentInfo.self, data: responseData) - expect(environmentInfo?.sdkVersion).toEventually(equal("5.3.0")) + expect(environmentInfo?.sdkVersion).toEventually(equal("5.3.1")) expect(environmentInfo?.hostVersion).toEventually(equal(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String)) expect(environmentInfo?.hostLocale).toEventually(equal("en-US")) } diff --git a/USERGUIDE.md b/USERGUIDE.md index bbfa7623..67ea26bd 100644 --- a/USERGUIDE.md +++ b/USERGUIDE.md @@ -83,7 +83,7 @@ To integrate MiniApp SDK into your Xcode project using Swift Package Manager, ad ```ruby dependencies: [ - .package(url: "https://github.com/rakutentech/ios-miniapp.git", .upToNextMajor(from: "5.3.0")) + .package(url: "https://github.com/rakutentech/ios-miniapp.git", .upToNextMajor(from: "5.3.1")) ] ``` From 4120fd9382452a517bfac78733ca18a3ac003ac1 Mon Sep 17 00:00:00 2001 From: Leo Date: Tue, 1 Aug 2023 15:11:23 +0900 Subject: [PATCH 2/4] MAAnalyticsInfo fix --- CHANGELOG.md | 1 + Sources/Classes/core/Models/MAAnalyticsInfo.swift | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21881548..2e2e6ded 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ **SDK** - **Feature:** Updated `loadFromBundle(miniAppManifest:completionHandler)` interface with optional MiniAppManifest object. - **Feature:** Added a new property in MiniAppViewable class to Enable/Disable 3D touch for the Miniapp that is launched. +- **Fix:** Enable variables to public for `MAAnalyticsInfo` **Sample App** - **Feature:** Updated Sample app to send `miniAppManifest` while loading from bundle diff --git a/Sources/Classes/core/Models/MAAnalyticsInfo.swift b/Sources/Classes/core/Models/MAAnalyticsInfo.swift index 0f23c8a3..05658479 100644 --- a/Sources/Classes/core/Models/MAAnalyticsInfo.swift +++ b/Sources/Classes/core/Models/MAAnalyticsInfo.swift @@ -16,12 +16,12 @@ public enum MAAnalyticsActionType: String, Codable { } public class MAAnalyticsInfo: Codable { - let eventType: MAAnalyticsEventType - let actionType: MAAnalyticsActionType - let pageName: String - let componentName: String - let elementType: String - let data: String + public let eventType: MAAnalyticsEventType + public let actionType: MAAnalyticsActionType + public let pageName: String + public let componentName: String + public let elementType: String + public let data: String public init(eventType: MAAnalyticsEventType, actionType: MAAnalyticsActionType, From 211849443fb2a9a679c5029fe379c2ee0e7dec3f Mon Sep 17 00:00:00 2001 From: Leo Date: Wed, 2 Aug 2023 14:19:05 +0900 Subject: [PATCH 3/4] Updated marketing version --- CHANGELOG.md | 2 +- MiniAppCarthage/MiniApp/MiniApp.xcodeproj/project.pbxproj | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e2e6ded..60bc0d62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## CHANGELOG -### 5.3.1 (2023-08-01) +### 5.3.1 (2023-08-02) **SDK** - **Feature:** Updated `loadFromBundle(miniAppManifest:completionHandler)` interface with optional MiniAppManifest object. - **Feature:** Added a new property in MiniAppViewable class to Enable/Disable 3D touch for the Miniapp that is launched. diff --git a/MiniAppCarthage/MiniApp/MiniApp.xcodeproj/project.pbxproj b/MiniAppCarthage/MiniApp/MiniApp.xcodeproj/project.pbxproj index b40e3b30..a5028218 100644 --- a/MiniAppCarthage/MiniApp/MiniApp.xcodeproj/project.pbxproj +++ b/MiniAppCarthage/MiniApp/MiniApp.xcodeproj/project.pbxproj @@ -1332,7 +1332,7 @@ "@executable_path/Frameworks", ); MACH_O_TYPE = staticlib; - MARKETING_VERSION = 5.3.0; + MARKETING_VERSION = 5.3.1; OTHER_LDFLAGS = "-ObjC"; PRODUCT_BUNDLE_IDENTIFIER = com.rakuten.tech.mobile.MiniApp; PRODUCT_NAME = MiniApp; @@ -1361,7 +1361,7 @@ "@executable_path/Frameworks", ); MACH_O_TYPE = staticlib; - MARKETING_VERSION = 5.3.0; + MARKETING_VERSION = 5.3.1; OTHER_LDFLAGS = "-ObjC"; PRODUCT_BUNDLE_IDENTIFIER = com.rakuten.tech.mobile.MiniApp; PRODUCT_NAME = MiniApp; From 8f94535c6567f8072f0ed6fc674b1433ec69d865 Mon Sep 17 00:00:00 2001 From: Leo Date: Mon, 28 Aug 2023 18:00:56 +0900 Subject: [PATCH 4/4] Update release date --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7784a26..14791a74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## CHANGELOG -### 5.4.0 (2023-08-29) +### 5.4.0 (2023-08-28) **SDK** - **Feature:** Added a new interface `downloadMiniApp(appId:versionId:completionHandler:)` to download Miniapp from platform in background if needed. - **Feature:** Added a utility method to know if Miniapp has beend downloaded properly. `isMiniAppCacheAvailable(appId: String, versionId:)`