-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: web view app with two different variant using SwiftUI and UIKit
- Loading branch information
Showing
31 changed files
with
1,455 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
WebView/SwiftUI/WebViewApp.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...ew/SwiftUI/WebViewApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
15 changes: 15 additions & 0 deletions
15
...ew/SwiftUI/WebViewApp.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"originHash" : "55df34735be77dde4d92b13fbd90e1b9ab472fa212519a415a896f5c0e895487", | ||
"pins" : [ | ||
{ | ||
"identity" : "appsflyerframework-static", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/AppsFlyerSDK/AppsFlyerFramework-Static", | ||
"state" : { | ||
"revision" : "ee61c7cd170e72235d9c029ec7df69aaa5a4b623", | ||
"version" : "6.15.2" | ||
} | ||
} | ||
], | ||
"version" : 3 | ||
} |
11 changes: 11 additions & 0 deletions
11
WebView/SwiftUI/WebViewApp/Assets.xcassets/AccentColor.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
WebView/SwiftUI/WebViewApp/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"platform" : "ios", | ||
"size" : "1024x1024" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// ContentView.swift | ||
// WebViewApp | ||
// | ||
// Created by Mustafa Bekirov on 11.09.2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ContentView: View { | ||
@State private var isLoading = true | ||
|
||
var body: some View { | ||
Group { | ||
if isLoading { | ||
LaunchView() | ||
.onAppear { | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 2) { | ||
isLoading = false | ||
} | ||
} | ||
} else { | ||
WebViewView() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// Config.swift | ||
// WebViewApp | ||
// | ||
// Created by Mustafa Bekirov on 11.09.2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
enum Config { | ||
static let appId = "id666666668" | ||
static let uniqueKey = "xzHEvYwbEeF9xVcVGoGNFE" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// WebView.swift | ||
// WebViewApp | ||
// | ||
// Created by Mustafa Bekirov on 11.09.2024. | ||
// | ||
|
||
import SwiftUI | ||
import WebKit | ||
|
||
struct WebView: UIViewRepresentable { | ||
let urlString: String | ||
|
||
func makeUIView(context: Context) -> WKWebView { | ||
// Creating WKWebpagePreferences to enable JavaScript | ||
let preferences = WKWebpagePreferences() | ||
preferences.allowsContentJavaScript = true // Enable JavaScript in the web page | ||
|
||
// Configuring WKWebView | ||
let configuration = WKWebViewConfiguration() | ||
configuration.defaultWebpagePreferences = preferences // Apply preferences for JavaScript | ||
configuration.websiteDataStore = WKWebsiteDataStore.default() // Enable third-party cookies | ||
|
||
// Initializing WKWebView with the specified configuration | ||
let webView = WKWebView(frame: .zero, configuration: configuration) | ||
webView.allowsBackForwardNavigationGestures = true // Allow swipe gestures for back/forward navigation | ||
|
||
return webView | ||
} | ||
|
||
func updateUIView(_ webView: WKWebView, context: Context) { | ||
// Load the provided URL if it's valid | ||
if let url = URL(string: urlString) { | ||
webView.load(URLRequest(url: url)) // Load the URL request in the web view | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// LaunchView.swift | ||
// WebViewApp | ||
// | ||
// Created by Mustafa Bekirov on 11.09.2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct LaunchView: View { | ||
@State private var ballOffset: CGFloat = -100 | ||
@State private var isBouncing = false | ||
|
||
var body: some View { | ||
VStack { | ||
Circle() | ||
.fill(Color.blue) | ||
.frame(width: 50, height: 50) | ||
.offset(y: ballOffset) | ||
.onAppear { | ||
withAnimation(Animation.easeInOut(duration: 0.5).repeatForever(autoreverses: true)) { | ||
ballOffset = 100 | ||
} | ||
} | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
WebView/SwiftUI/WebViewApp/Preview Content/Preview Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// WebViewAppApp.swift | ||
// WebViewApp | ||
// | ||
// Created by Mustafa Bekirov on 11.09.2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@main | ||
struct WebViewAppApp: App { | ||
var body: some Scene { | ||
WindowGroup { | ||
ContentView() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// WebViewView.swift | ||
// WebViewApp | ||
// | ||
// Created by Mustafa Bekirov on 11.09.2024. | ||
// | ||
|
||
import SwiftUI | ||
import AdSupport | ||
import AppsFlyerLib | ||
|
||
struct WebViewView: View { | ||
@State private var urlString: String = "" | ||
@State private var advertisingId: String = "" | ||
@State private var appsflyerId: String = "" | ||
@State private var conversionData: [String: Any] = [:] | ||
|
||
var body: some View { | ||
VStack { | ||
TextField("Enter URL", text: $urlString) | ||
.textFieldStyle(RoundedBorderTextFieldStyle()) | ||
.padding() | ||
.onSubmit { | ||
let requestBody = createRequestBody( | ||
url: urlString, | ||
advertisingId: advertisingId, | ||
appsflyerId: appsflyerId, | ||
conversionData: conversionData | ||
) | ||
|
||
print("Request Body: \(requestBody)") // Debug: printing the request body for verification | ||
|
||
hideKeyboard() // Hide the keyboard after URL submission | ||
} | ||
|
||
WebView(urlString: urlString) | ||
.edgesIgnoringSafeArea(.all) // Ensuring the WebView uses the entire screen | ||
} | ||
.onAppear { | ||
collectDeviceData() // Gathering device data when the view appears | ||
} | ||
} | ||
|
||
// Function to create a request body with URL and device info | ||
func createRequestBody(url: String, advertisingId: String, appsflyerId: String, conversionData: [String: Any]) -> [String: Any] { | ||
return [ | ||
"url": url, | ||
"advertisingId": advertisingId, | ||
"appsflyerId": appsflyerId, | ||
"conversionData": conversionData, | ||
"appId": Config.appId, | ||
"uniqueKey": Config.uniqueKey | ||
] | ||
} | ||
|
||
// Collect device data like Advertising ID and AppsFlyer details | ||
func collectDeviceData() { | ||
advertisingId = ASIdentifierManager.shared().advertisingIdentifier.uuidString | ||
|
||
AppsFlyerLib.shared().start { response, error in | ||
if let error = error { | ||
print("Error: \(error.localizedDescription)") // Log an error if AppsFlyer fails | ||
} else if let response = response { | ||
appsflyerId = response["appsflyer_id"] as? String ?? "" // Extract AppsFlyer ID | ||
conversionData = response // Store the conversion data | ||
print("Appsflyer Data: \(conversionData)") // Debug: print the collected data | ||
} | ||
} | ||
|
||
print("Advertising ID: \(advertisingId)") // Debug: print the Advertising ID | ||
} | ||
|
||
// Function to hide the keyboard | ||
private func hideKeyboard() { | ||
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) | ||
} | ||
} |
Oops, something went wrong.