@superfan-app/spotify-auth 0.1.43 → 0.1.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ios/SpotifyOAuthView.swift +58 -40
- package/package.json +1 -1
|
@@ -57,50 +57,68 @@ class SpotifyOAuthView: ExpoView {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
private func setupWebView() {
|
|
60
|
+
// Ensure we're on the main thread for UI setup
|
|
61
|
+
guard Thread.isMainThread else {
|
|
62
|
+
DispatchQueue.main.async { [weak self] in
|
|
63
|
+
self?.setupWebView()
|
|
64
|
+
}
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
|
|
60
68
|
// Create a configuration that prevents data persistence
|
|
61
|
-
let config =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
let dataStore = WKWebsiteDataStore.nonPersistent()
|
|
68
|
-
config.websiteDataStore = dataStore
|
|
69
|
-
|
|
70
|
-
webView = WKWebView(frame: .zero, configuration: config)
|
|
71
|
-
webView.navigationDelegate = self
|
|
72
|
-
webView.allowsBackForwardNavigationGestures = true
|
|
73
|
-
webView.customUserAgent = "SpotifyAuth-iOS/1.0" // Custom UA to identify our app
|
|
74
|
-
|
|
75
|
-
// Add loading indicator
|
|
76
|
-
let activityIndicator = UIActivityIndicatorView(style: .medium)
|
|
77
|
-
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
|
|
78
|
-
activityIndicator.hidesWhenStopped = true
|
|
79
|
-
|
|
80
|
-
addSubview(webView)
|
|
81
|
-
addSubview(activityIndicator)
|
|
82
|
-
|
|
83
|
-
// Setup constraints
|
|
84
|
-
webView.translatesAutoresizingMaskIntoConstraints = false
|
|
85
|
-
NSLayoutConstraint.activate([
|
|
86
|
-
webView.topAnchor.constraint(equalTo: topAnchor),
|
|
87
|
-
webView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
88
|
-
webView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
89
|
-
webView.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
69
|
+
let config: WKWebViewConfiguration = {
|
|
70
|
+
let configuration = WKWebViewConfiguration()
|
|
71
|
+
configuration.processPool = WKProcessPool() // Create a new process pool
|
|
72
|
+
let prefs = WKWebpagePreferences()
|
|
73
|
+
prefs.allowsContentJavaScript = true
|
|
74
|
+
configuration.defaultWebpagePreferences = prefs
|
|
90
75
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
76
|
+
// Ensure cookies and data are not persisted
|
|
77
|
+
let dataStore = WKWebsiteDataStore.nonPersistent()
|
|
78
|
+
configuration.websiteDataStore = dataStore
|
|
79
|
+
return configuration
|
|
80
|
+
}()
|
|
81
|
+
|
|
82
|
+
// Initialize webview on main thread with error handling
|
|
83
|
+
do {
|
|
84
|
+
webView = WKWebView(frame: .zero, configuration: config)
|
|
85
|
+
webView.navigationDelegate = self
|
|
86
|
+
webView.allowsBackForwardNavigationGestures = true
|
|
87
|
+
webView.customUserAgent = "SpotifyAuth-iOS/1.0" // Custom UA to identify our app
|
|
88
|
+
|
|
89
|
+
// Add loading indicator
|
|
90
|
+
let activityIndicator = UIActivityIndicatorView(style: .medium)
|
|
91
|
+
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
|
|
92
|
+
activityIndicator.hidesWhenStopped = true
|
|
93
|
+
|
|
94
|
+
addSubview(webView)
|
|
95
|
+
addSubview(activityIndicator)
|
|
96
|
+
|
|
97
|
+
// Setup constraints
|
|
98
|
+
webView.translatesAutoresizingMaskIntoConstraints = false
|
|
99
|
+
NSLayoutConstraint.activate([
|
|
100
|
+
webView.topAnchor.constraint(equalTo: topAnchor),
|
|
101
|
+
webView.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
102
|
+
webView.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
103
|
+
webView.bottomAnchor.constraint(equalTo: bottomAnchor),
|
|
104
|
+
|
|
105
|
+
activityIndicator.centerXAnchor.constraint(equalTo: centerXAnchor),
|
|
106
|
+
activityIndicator.centerYAnchor.constraint(equalTo: centerYAnchor)
|
|
107
|
+
])
|
|
108
|
+
|
|
109
|
+
// Setup modern KVO observation
|
|
110
|
+
observerToken = webView.observe(\.isLoading, options: [.new]) { [weak self] _, _ in
|
|
111
|
+
if let activityIndicator = self?.subviews.first(where: { $0 is UIActivityIndicatorView }) as? UIActivityIndicatorView {
|
|
112
|
+
if self?.webView.isLoading == true {
|
|
113
|
+
activityIndicator.startAnimating()
|
|
114
|
+
} else {
|
|
115
|
+
activityIndicator.stopAnimating()
|
|
116
|
+
}
|
|
102
117
|
}
|
|
103
118
|
}
|
|
119
|
+
} catch {
|
|
120
|
+
secureLog("Failed to setup WebView: \(error.localizedDescription)")
|
|
121
|
+
delegate?.oauthView(self, didFailWithError: SpotifyOAuthError.authorizationError("Failed to initialize web view"))
|
|
104
122
|
}
|
|
105
123
|
}
|
|
106
124
|
|