Skip to content

Commit

Permalink
feat: web view app with two different variant using SwiftUI and UIKit
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafos committed Sep 11, 2024
1 parent 759151d commit 259dafc
Show file tree
Hide file tree
Showing 31 changed files with 1,455 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file added WebView/.DS_Store
Binary file not shown.
402 changes: 402 additions & 0 deletions WebView/SwiftUI/WebViewApp.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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>
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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
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
}
}
6 changes: 6 additions & 0 deletions WebView/SwiftUI/WebViewApp/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
27 changes: 27 additions & 0 deletions WebView/SwiftUI/WebViewApp/ContentView.swift
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()
}
}
}
}
13 changes: 13 additions & 0 deletions WebView/SwiftUI/WebViewApp/Helpers/Config.swift
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"
}
37 changes: 37 additions & 0 deletions WebView/SwiftUI/WebViewApp/Helpers/WebView.swift
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
}
}
}
27 changes: 27 additions & 0 deletions WebView/SwiftUI/WebViewApp/LaunchView.swift
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
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
17 changes: 17 additions & 0 deletions WebView/SwiftUI/WebViewApp/WebViewAppApp.swift
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()
}
}
}
77 changes: 77 additions & 0 deletions WebView/SwiftUI/WebViewApp/WebViewView.swift
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)
}
}
Loading

0 comments on commit 259dafc

Please sign in to comment.