Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK enhancements #20

Merged
merged 16 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Example/ImageKit/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
_ = ImageKit.init(publicKey: "your_public_key", imageKitEndpoint: "https://ik.imagekit.io/your_imagekit_id", transformationPosition: TransformationPosition.PATH, authenticationEndpoint: "http://localhost:8080/auth")
ImageKit.init(publicKey: "IK_PUBLIC_KEY", urlEndpoint: "https://ik.imagekit.io/IK_ID", transformationPosition: TransformationPosition.PATH)
ahnv marked this conversation as resolved.
Show resolved Hide resolved
return true
}

Expand Down
14 changes: 4 additions & 10 deletions Example/ImageKit/FetchImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,22 @@ class FetchImageViewController: UIViewController {
}

@IBAction func OnClickTransformation3(_ sender: Any) {
let url = ImageKit.shared.url(src: "https://ik.imagekit.io/demo/medium_cafe_B1iTdD0C.jpg", transformationPosition: TransformationPosition.PATH)
.overlayImage(overlayImage: "logo-white_SJwqB4Nfe.png")
.overlayX(overlayX: 10)
.overlayY(overlayY: 20)
.create()
guard let url = try? ImageKit.shared.url(src: "https://ik.imagekit.io/demo/medium_cafe_B1iTdD0C.jpg", transformationPosition: TransformationPosition.PATH)
.setResponsive(view: imageView)
.create() else { return }
ahnv marked this conversation as resolved.
Show resolved Hide resolved
self.showImage(url: url)
}

@IBAction func OnClickTransformation4(_ sender: Any) {
let url = ImageKit.shared.url(src: "https://ik.imagekit.io/demo/tr:oi-logo-white_SJwqB4Nfe.png,ox-N10,oy-20/medium_cafe_B1iTdD0C.jpg")
.raw(params: "l-text,i-ik_logo.png,lx-20,ly-20,r-32,l-end")
.create()
ahnv marked this conversation as resolved.
Show resolved Hide resolved
self.showImage(url: url)
}

@IBAction func OnClickTransformation5(_ sender: Any) {
let url = ImageKit.shared.url(src: "https://ik.imagekit.io/demo/img/plant.jpeg?tr=oi-logo-white_SJwqB4Nfe.png,ox-10,oy-20")
.addCustomTransformation(key: "w", value: "400")
ahnv marked this conversation as resolved.
Show resolved Hide resolved
.overlayText(overlayText: "Hand with a green plant")
.overlayTextColor(overlayTextColor: "264120")
.overlayTextFontSize(overlayTextSize: 30)
.overlayX(overlayX: 10)
.overlayY(overlayY: 20)
.create()
self.showImage(url: url)
}
Expand Down
42 changes: 21 additions & 21 deletions Example/ImageKit/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>localhost:8000</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSAppleMusicUsageDescription</key>
<string>Media Library Access Warning</string>
<key>NSCameraUsageDescription</key>
<string>Camera Access Warning</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Photo Library Access Warning</string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -43,6 +22,27 @@
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>localhost:8000</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
<key>NSAppleMusicUsageDescription</key>
<string>Media Library Access Warning</string>
<key>NSCameraUsageDescription</key>
<string>Camera Access Warning</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Photo Library Access Warning</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand Down
48 changes: 48 additions & 0 deletions Example/ImageKit/UploadAuthService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// UploadAuthService.swift
// ImageKit_Example
//
// Created by Animesh Verma on 25/09/23.
// Copyright © 2023 CocoaPods. All rights reserved.
//

import Foundation

class UploadAuthService {
static let dispatchGroup = DispatchGroup()

static func getUploadToken(payload: [String : String]) -> [String : String]? {
let urlSession = URLSession(configuration: URLSessionConfiguration.default, delegate: URLSession.shared.delegate, delegateQueue: URLSession.shared.delegateQueue)
var request = URLRequest(url: URL(string: "AUTH_SERVER_HOST")!)
request.httpMethod = "POST"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
var tokenResponse: [String : String]? = nil
guard let body = try? JSONSerialization.data(withJSONObject: ["uploadPayload": payload, "expire": 60, "publicKey": "IK_PUBLIC_KEY"] as [String : Any]) else {
ahnv marked this conversation as resolved.
Show resolved Hide resolved
return nil
}
request.httpBody = body
dispatchGroup.enter()
DispatchQueue.global().async {
let task = urlSession.dataTask(with: request) { data, response, error in
guard error == nil else {
dispatchGroup.leave()
print(error)
return
}
let response = response as! HTTPURLResponse
let status = response.statusCode
guard (200...299).contains(status) else {
dispatchGroup.leave()
return
}
if let data = data {
tokenResponse = try? (JSONSerialization.jsonObject(with: data) as! [String : String])
}
dispatchGroup.leave()
}
task.resume()
}
dispatchGroup.wait()
return tokenResponse
}
}
70 changes: 47 additions & 23 deletions Example/ImageKit/UploadFileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,56 @@ class UploadFileViewController: UIViewController {
@IBAction func OnClickUpload(_ sender: Any) {
do{
let filename = self.fileUrlToBeUploaded!.lastPathComponent
fileUrlToBeUploaded!.startAccessingSecurityScopedResource()
let file = try NSData(contentsOf: self.fileUrlToBeUploaded!) as Data
let progressAlert = showProgressToast(title: "Uploading", message: "Please Wait")
ImageKit.shared.uploader().upload(
file: file,
fileName: filename,
useUniqueFilename: true,
tags: ["demo","file"],
folder: "/",
signatureHeaders: ["x-test-header":"Test"],
progress: { progress in
let progressBar: UIProgressView? = progressAlert.view.subviews.filter{$0 is UIProgressView}.first as? UIProgressView
if (progressBar != nil){
progressBar!.setProgress(Float(progress.fractionCompleted), animated: true)
let tokenResponse = UploadAuthService.getUploadToken(payload: [
"fileName" : filename,
"useUniqueFileName" : "true",
"tags" : ["demo","file"].joined(separator: ","),
"folder" : "/",
])
if let token = tokenResponse?["token"] {
ImageKit.shared.uploader().upload(
file: file,
token: token,
fileName: filename,
useUniqueFilename: true,
tags: ["demo","file"],
folder: "/",
progress: { progress in
let progressBar: UIProgressView? = progressAlert.view.subviews.filter{$0 is UIProgressView}.first as? UIProgressView
if (progressBar != nil){
progressBar!.setProgress(Float(progress.fractionCompleted), animated: true)
}
},
preprocessor: VideoUploadPreprocessor.Builder()
.limit(width: 800, height: 600)
.frameRate(frameRateValue: 60)
.keyFramesInterval(interval: 6)
.targetVideoBitrateKbps(targetVideoBitrateKbps: 480)
.targetAudioBitrateKbps(targetAudioBitrateKbps: 320)
.build(),
completion: { result in
DispatchQueue.main.async {
self.dismiss(animated: true, completion: {
switch result {
case .success((_, let uploadAPIResponse)):
self.showToast(title: "Upload Complete", message: "The uploaded file can be accessed using url: " + (uploadAPIResponse?.url!)!)
case .failure(let error as UploadAPIError):
self.showToast(title: "Upload Failed", message: "Error: " + error.message)
case .failure(let error):
self.showToast(title: "Upload Failed", message: "Error: " + error.localizedDescription)
}
})
}
}
},
completion: { result in
self.dismiss(animated: true)
switch result{
case .success((_, let uploadAPIResponse)):
self.showToast(title: "Upload Complete", message: "The uploaded file can be accessed using url: " + (uploadAPIResponse?.url!)!)
case .failure(let error as UploadAPIError):
self.showToast(title: "Upload Failed", message: "Error: " + error.message)
case .failure(let error):
self.showToast(title: "Upload Failed", message: "Error: " + error.localizedDescription)
}
})
)
} else {
self.dismiss(animated: true, completion: {
self.showToast(title: "Upload Failed", message: "Failed to fetch upload token")
})
}
} catch {
print(error)
}
Expand Down
77 changes: 54 additions & 23 deletions Example/ImageKit/UploadImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,61 @@ class UploadImageViewController: UIViewController{
let image: UIImage = self.imageView.image!
let imageName = image.accessibilityIdentifier!
let progressAlert = showProgressToast(title: "Uploading", message: "Please Wait")
ImageKit.shared.uploader().upload(
file: image,
fileName: imageName,
useUniqueFilename: true,
tags: ["demo","image"],
folder: "/",
signatureHeaders: ["x-test-header":"Test"],
progress: { progress in
let progressBar: UIProgressView? = progressAlert.view.subviews.filter{$0 is UIProgressView}.first as? UIProgressView
if (progressBar != nil){
progressBar!.setProgress(Float(progress.fractionCompleted), animated: true)

let tokenResponse = UploadAuthService.getUploadToken(payload: [
"fileName" : imageName,
"useUniqueFileName" : "true",
"tags" : ["demo","image"].joined(separator: ","),
"folder" : "/",
])
if let token = tokenResponse?["token"] {
ImageKit.shared.uploader().upload(
file: image,
token: token,
fileName: imageName,
useUniqueFilename: true,
tags: ["demo","image"],
folder: "/",
progress: { progress in
let progressBar: UIProgressView? = progressAlert.view.subviews.filter{$0 is UIProgressView}.first as? UIProgressView
if (progressBar != nil){
progressBar!.setProgress(Float(progress.fractionCompleted), animated: true)
}
},
policy: UploadPolicy.Builder()
.requireNetworkType(.UNMETERED)
.requiresBatteryCharging(true)
.maxRetries(4)
.backoffCriteria(backoffMillis: 500, backoffPolicy: .EXPONENTIAL)
.build(),
preprocessor: ImageUploadPreprocessor<UIImage>.Builder()
.limit(width: 400, height: 300)
.rotate(degrees: 45)
.format(format: .JPEG)
.build(),
completion: { result in
DispatchQueue.main.async {
self.dismiss(animated: true, completion: {
switch result {
case .success(( _, let uploadAPIResponse)):
self.showToast(title: "Upload Complete", message: "The uploaded image can be accessed using url: " + (uploadAPIResponse?.url!)!)
case .failure(let error as UploadAPIError):
self.showToast(title: "Upload Failed", message: "Error: " + error.message)
case .failure(let error):
self.showToast(title: "Upload Failed", message: "Error: " + error.localizedDescription)
}
}
)
}
}
},
completion: { result in
self.dismiss(animated: true)
switch result{
case .success(( _, let uploadAPIResponse)):
self.showToast(title: "Upload Complete", message: "The uploaded image can be accessed using url: " + (uploadAPIResponse?.url!)!)
case .failure(let error as UploadAPIError):
self.showToast(title: "Upload Failed", message: "Error: " + error.message)
case .failure(let error):
self.showToast(title: "Upload Failed", message: "Error: " + error.localizedDescription)
}
})
)
} else {
DispatchQueue.main.async {
self.dismiss(animated: true, completion: {
self.showToast(title: "Upload Failed", message: "Failed to fetch upload token")
})
}
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,21 @@ use_frameworks!
target 'ImageKit_Example' do
pod 'ImageKitIO', :path => '../', :testspecs => ['Tests']
end

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0'
end
end
installer.pods_project.targets.each do |target|
if target.name == "Nimble"
target.build_configurations.each do |config|
xcconfig_path = config.base_configuration_reference.real_path
xcconfig = File.read(xcconfig_path)
new_xcconfig = xcconfig.sub('lswiftXCTest', 'lXCTestSwiftSupport')
File.open(xcconfig_path, "w") { |file| file << new_xcconfig }
end
end
end
end
30 changes: 15 additions & 15 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
PODS:
- ImageKitIO (2.0.0)
- ImageKitIO/Tests (2.0.0):
- Kakapo
- Nimble (~> 7.0)
- Quick (~> 1.2.0)
- Kakapo (2.1.0)
- Nimble (7.3.4)
- Quick (1.2.0)
- ImageKitIO (3.0.0)
- ImageKitIO/Tests (3.0.0):
- Nimble (~> 10.0.0)
- Quick (~> 5.0.1)
- Swifter (~> 1.5.0)
- Nimble (10.0.0)
- Quick (5.0.1)
- Swifter (1.5.0)

DEPENDENCIES:
- ImageKitIO (from `../`)
- ImageKitIO/Tests (from `../`)

SPEC REPOS:
trunk:
- Kakapo
- Nimble
- Quick
- Swifter

EXTERNAL SOURCES:
ImageKitIO:
:path: "../"

SPEC CHECKSUMS:
ImageKitIO: e265556e071aa657d25fc3c33aad0bf1ae671474
Kakapo: a30b8f6ce2ce17eec2d441df923a2af0ec5f538f
Nimble: 051e3d8912d40138fa5591c78594f95fb172af37
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
ImageKitIO: c3a1eb6a86e7d9efa4b0fcc540d364e87e1d3e3e
Nimble: 5316ef81a170ce87baf72dd961f22f89a602ff84
Quick: 749aa754fd1e7d984f2000fe051e18a3a9809179
Swifter: e71dd674404923d7f03ebb03f3f222d1c570bc8e

PODFILE CHECKSUM: 2eba1966dbe76453f1bde8d84ee487f59549fb06
PODFILE CHECKSUM: e78309d88ca5261176c67541261c22ae6900a730

COCOAPODS: 1.9.1
COCOAPODS: 1.14.3
Loading
Loading