Skip to content

Commit

Permalink
Swift6対応としてInAppMessagingDelegateの関数をMainActorに隔離 (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
tikidunpon authored Sep 21, 2024
1 parent 7703139 commit 8361992
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 28 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
| モジュール名 | Description | 最新のバージョン |
| :-- | :-- | :-- |
| KarteCore | イベントトラッキング機能を提供します。 | 2.30.0 |
| KarteInAppMessaging | アプリ内メッセージ機能を提供します。 | 2.18.0 |
| KarteInAppMessaging | アプリ内メッセージ機能を提供します。 | 2.19.0 |
| KarteRemoteNotification | プッシュ通知の受信および効果測定機能を提供します。 | 2.11.0 |
| KarteVariables | 設定値配信機能を提供します。 | 2.10.0 |
| KarteVisualTracking | ビジュアルトラッキング機能を提供します。 | 2.12.0 |
Expand All @@ -17,6 +17,10 @@
** 🎉 FEATURE**
- Native機能呼び出しにATT許諾ダイアログ表示を追加しました。

### InAppMessaging 2.19.0
** 🔨CHANGED**
- InAppMessagingDelegateの処理をMainActorに隔離しました。

# Releases - 2024.08.26
## Version 2.17.0

Expand Down
4 changes: 2 additions & 2 deletions Karte.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3928,7 +3928,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.18.0;
MARKETING_VERSION = 2.19.0;
PRODUCT_BUNDLE_IDENTIFIER = io.karte.KarteInAppMessaging;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -3961,7 +3961,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2.18.0;
MARKETING_VERSION = 2.19.0;
PRODUCT_BUNDLE_IDENTIFIER = io.karte.KarteInAppMessaging;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
Expand Down
2 changes: 1 addition & 1 deletion KarteInAppMessaging.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'KarteInAppMessaging'
s.version = '2.18.0'
s.version = '2.19.0'
s.summary = 'KARTE In-app messaging SDK'
s.homepage = 'https://karte.io'
s.author = { 'PLAID' => '[email protected]' }
Expand Down
9 changes: 8 additions & 1 deletion KarteInAppMessaging/IAMProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,13 @@ extension IAMProcess {

private func handleJsMessageEvent(_ data: JsMessage.EventData) {
Tracker.track(view: window, data: data)
notifyCampaignOpenOrClose(data)
if Thread.isMainThread {
notifyCampaignOpenOrClose(data)
} else {
DispatchQueue.main.async {
self.notifyCampaignOpenOrClose(data)
}
}
}

private func handleJsMessageOpenURL(_ data: JsMessage.OpenURLData) {
Expand Down Expand Up @@ -347,6 +353,7 @@ extension IAMProcess: IAMWebViewDelegate {
return true
}

@MainActor
func inAppMessagingWebView(_ webView: IAMWebView, shouldOpenURL url: URL) -> Bool {
let iam = InAppMessaging.shared
guard let delegate = iam.delegate else {
Expand Down
4 changes: 2 additions & 2 deletions KarteInAppMessaging/InAppMessaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ extension InAppMessaging {
}
}

@objc
@MainActor @objc
private func observeWindowDidBecomeVisibleNotification(_ notification: Notification) {
guard let window = notification.object as? UIWindow else {
return
Expand Down Expand Up @@ -255,7 +255,7 @@ extension InAppMessaging {
pool.storeProcess(process)
}

@objc
@MainActor @objc
private func observeWindowDidBecomeHiddenNotification(_ notification: Notification) {
guard let window = notification.object as? UIWindow else {
return
Expand Down
2 changes: 1 addition & 1 deletion KarteInAppMessaging/InAppMessagingDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import UIKit

/// アプリ内メッセージで発生するイベントを委譲するためのタイプです。
@objc(KRTInAppMessagingDelegate)
@preconcurrency @MainActor @objc(KRTInAppMessagingDelegate)
public protocol InAppMessagingDelegate: AnyObject {
/// アプリ内メッセージ用のWindowが表示されたことを通知します。
///
Expand Down
42 changes: 22 additions & 20 deletions KarteInAppMessaging/View/IAMWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,34 +172,36 @@ internal class IAMWebView: WKWebView {
}

func openURL(_ url: URL?, isReset: Bool) {
guard let url = url else {
Logger.debug(tag: .inAppMessaging, message: "Can't open URL because URL is nil.")
return
}
DispatchQueue.main.async {
guard let url = url else {
Logger.debug(tag: .inAppMessaging, message: "Can't open URL because URL is nil.")
return
}

if isReset {
reset(mode: .soft)
}
if isReset {
self.reset(mode: .soft)
}

if let delegate = delegate, !delegate.inAppMessagingWebView(self, shouldOpenURL: url) {
Logger.info(tag: .inAppMessaging, message: "SDK delegates openURL to client app. URL=\(url)")
return
}
if let delegate = self.delegate, !delegate.inAppMessagingWebView(self, shouldOpenURL: url) {
Logger.info(tag: .inAppMessaging, message: "SDK delegates openURL to client app. URL=\(url)")
return
}

if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:]) { successful in
if successful {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:]) { successful in
if successful {
Logger.info(tag: .inAppMessaging, message: "Success to open URL: \(url)")
} else {
Logger.error(tag: .inAppMessaging, message: "Failed to open URL: \(url)")
}
}
} else {
if UIApplication.shared.openURL(url) {
Logger.info(tag: .inAppMessaging, message: "Success to open URL: \(url)")
} else {
Logger.error(tag: .inAppMessaging, message: "Failed to open URL: \(url)")
}
}
} else {
if UIApplication.shared.openURL(url) {
Logger.info(tag: .inAppMessaging, message: "Success to open URL: \(url)")
} else {
Logger.error(tag: .inAppMessaging, message: "Failed to open URL: \(url)")
}
}
}

Expand Down

0 comments on commit 8361992

Please sign in to comment.