Skip to content

Commit

Permalink
Merge pull request #20 from imagekit-developer/develop
Browse files Browse the repository at this point in the history
SDK enhancements
  • Loading branch information
ahnv authored Jun 11, 2024
2 parents 39526ba + 0360a1f commit 2870683
Show file tree
Hide file tree
Showing 42 changed files with 1,641 additions and 1,545 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ jobs:
- name: Build Example Project
run: |
cd Example
xcodebuild -workspace ImageKit.xcworkspace -scheme imagekit-Example -destination 'platform=iOS Simulator,name=iPhone 11' clean build
xcodebuild -workspace ImageKit.xcworkspace -scheme ImageKit-Example -destination 'platform=iOS Simulator,name=iPhone 15' clean build CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
- name: Run Tests
run: |
cd Example
xcodebuild -workspace ImageKit.xcworkspace -scheme imagekit-Example -destination 'platform=iOS Simulator,name=iPhone 11' -enableCodeCoverage YES clean test
xcodebuild -workspace ImageKit.xcworkspace -scheme ImageKit-Example -destination 'platform=iOS Simulator,name=iPhone 15' -enableCodeCoverage YES clean test CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
- name: Upload Coverage to codecov
run: bash <(curl -s https://codecov.io/bash) -J '^ImageKitIO$' -X coveragepy
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ language: objective-c
# - gem install cocoapods # Since Travis is not always on latest version
# - pod install --project-directory=Example
script:
- set -o pipefail && xcodebuild test -enableCodeCoverage YES -workspace Example/imagekit.xcworkspace -scheme imagekit-Example -sdk iphonesimulator9.3 ONLY_ACTIVE_ARCH=NO | xcpretty
- set -o pipefail && xcodebuild test -enableCodeCoverage YES -workspace Example/ImageKit.xcworkspace -scheme ImageKit-Example -sdk iphonesimulator9.3 ONLY_ACTIVE_ARCH=NO | xcpretty
- pod lib lint
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; };
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; };
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
9C04050B2AC1A18B00C1F3D9 /* UploadAuthService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C04050A2AC1A18B00C1F3D9 /* UploadAuthService.swift */; };
9CA356EF2C11BF68008E924E /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9CA356EE2C11BF68008E924E /* Constants.swift */; };
EB911FFFC8BD49D1D7A80C22 /* Pods_ImageKit_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2993B9223C061718918257E1 /* Pods_ImageKit_Example.framework */; };
/* End PBXBuildFile section */

Expand All @@ -32,6 +34,8 @@
607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
7661EF116E06444B352B18F0 /* Pods-ImageKit_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ImageKit_Example.debug.xcconfig"; path = "Target Support Files/Pods-ImageKit_Example/Pods-ImageKit_Example.debug.xcconfig"; sourceTree = "<group>"; };
9C04050A2AC1A18B00C1F3D9 /* UploadAuthService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UploadAuthService.swift; sourceTree = "<group>"; };
9CA356EE2C11BF68008E924E /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
BFEF935EF71672E4888B2B32 /* Pods-ImageKit_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ImageKit_Example.release.xcconfig"; path = "Target Support Files/Pods-ImageKit_Example/Pods-ImageKit_Example.release.xcconfig"; sourceTree = "<group>"; };
E241CB24C39AE57AF48C37DC /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
E42E9C1BBFA4D2A7E3047029 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
Expand Down Expand Up @@ -89,6 +93,8 @@
607FACD31AFB9204008FA782 /* Supporting Files */,
5365B93624CD5CD800E75971 /* UploadFileViewController.swift */,
5365B93824CD5CE500E75971 /* UploadImageViewController.swift */,
9C04050A2AC1A18B00C1F3D9 /* UploadAuthService.swift */,
9CA356EE2C11BF68008E924E /* Constants.swift */,
);
name = "Example for ImageKit";
path = ImageKit;
Expand Down Expand Up @@ -241,6 +247,8 @@
5365B93724CD5CD800E75971 /* UploadFileViewController.swift in Sources */,
5365B93924CD5CE500E75971 /* UploadImageViewController.swift in Sources */,
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
9CA356EF2C11BF68008E924E /* Constants.swift in Sources */,
9C04050B2AC1A18B00C1F3D9 /* UploadAuthService.swift in Sources */,
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -378,6 +386,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = ImageKit/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
Expand All @@ -393,6 +402,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
INFOPLIST_FILE = ImageKit/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "ImageKit_Example.app"
BlueprintName = "ImageKit_Example"
ReferencedContainer = "container:imagekit.xcodeproj">
ReferencedContainer = "container:ImageKit.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
Expand All @@ -31,7 +31,7 @@
BlueprintIdentifier = "607FACE41AFB9204008FA782"
BuildableName = "ImageKit_Tests.xctest"
BlueprintName = "ImageKit_Tests"
ReferencedContainer = "container:imagekit.xcodeproj">
ReferencedContainer = "container:ImageKit.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
Expand All @@ -49,7 +49,7 @@
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "ImageKit_Example.app"
BlueprintName = "ImageKit_Example"
ReferencedContainer = "container:imagekit.xcodeproj">
ReferencedContainer = "container:ImageKit.xcodeproj">
</BuildableReference>
</MacroExpansion>
<CodeCoverageTargets>
Expand Down Expand Up @@ -95,7 +95,7 @@
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "ImageKit_Example.app"
BlueprintName = "ImageKit_Example"
ReferencedContainer = "container:imagekit.xcodeproj">
ReferencedContainer = "container:ImageKit.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
Expand All @@ -112,7 +112,7 @@
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "ImageKit_Example.app"
BlueprintName = "ImageKit_Example"
ReferencedContainer = "container:imagekit.xcodeproj">
ReferencedContainer = "container:ImageKit.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
Expand Down
3 changes: 0 additions & 3 deletions Example/ImageKit.xcworkspace/contents.xcworkspacedata

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

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: IK_URL_ENDPOINT, transformationPosition: TransformationPosition.PATH)
return true
}

Expand Down
21 changes: 21 additions & 0 deletions Example/ImageKit/Constants.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Constants.swift
// ImageKit_Example
//
// Created by Animesh Verma on 06/06/24.
// Copyright © 2024 CocoaPods. All rights reserved.
//

import Foundation

//Replace with ImageKit public key from ImageKit Dashboard (https://imagekit.io/dashboard/url-endpoints)
let IK_PUBLIC_KEY = "IK_PUBLIC_KEY"

//Replace with ImageKit URL endpoint (or CNAME) from ImageKit Dashboard (https://imagekit.io/dashboard/url-endpoints)
let IK_URL_ENDPOINT = "https://ik.imagekit.io/IMAGEKIT_ID"

//Replace with your custom server endpoint to get auth token for uploads
let AUTH_SERVER_API_ENDPOINT = "AUTH_SERVER_API_ENDPOINT"

//Replace with any image available in your ImageKit media library
let SAMPLE_IMAGE = "default-image.jpg"
22 changes: 9 additions & 13 deletions Example/ImageKit/FetchImageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,36 +31,32 @@ class FetchImageViewController: UIViewController {
}

@IBAction func OnClickTransformation2(_ sender: Any) {
let url = ImageKit.shared.url(path: "default-image.jpg", transformationPosition: TransformationPosition.QUERY)
let url = ImageKit.shared.url(path: SAMPLE_IMAGE, transformationPosition: TransformationPosition.QUERY)
.height(height: 400)
.aspectRatio(width: 3, height: 2)
.create()
self.showImage(url: url)
}

@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(urlEndpoint: "https://ik.imagekit.io/demo/img", path: "/medium_cafe_B1iTdD0C.jpg", transformationPosition: TransformationPosition.PATH)
.raw(params: "l-text,i-logo-white_SJwqB4Nfe.png,ox-10,l-end")
.setResponsive(view: imageView)
.create() else { return }
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")
let url = ImageKit.shared.url(src: "https://ik.imagekit.io/demo/medium_cafe_B1iTdD0C.jpg")
.raw(params: "l-image,i-logo-white_SJwqB4Nfe.png,lx-N20,ly-20,l-end")
.create()
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")
let url = ImageKit.shared.url(src: "https://ik.imagekit.io/demo/img/plant.jpeg")
.raw(params: "l-text,i-Hand%20with%20a%20green%20plant,co-264120,fs-30,lx-10,ly-20,l-end")
.addCustomTransformation(key: "w", value: "400")
.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_API_ENDPOINT)!)
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 {
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
Loading

0 comments on commit 2870683

Please sign in to comment.