top of page

DS Photo Editor SDK

A Photo Editor Built for Developers

Getting started with DS Photo Editor SDK for iOS (Swift)

This guide will show you how to integrate DS Photo Editor SDK into your iOS apps, within just minutes!

Prerequisites

1. Download the iOS SDK:

 

2. The following software is required:

  • Xcode 10 or higher

  • iOS 9 or higher

3. Since all the image tools in the SDK are GPU-accelerated and run close to real-time, you will need a real device to  see the performance of the SDK. Simulators will NOT work properly and are NOT able to indicate SDK performance.

Adding the SDK to an iOS Project

1. Switch to "General" tab in your target.

    Click "+" button under "Embedded Binaries".

    Click "Add Other" and then add the "DSPhotoEditorSDK.framework" you downloaded.

    You should see something similar to the screenshot below. You can also check the "Framework Search Paths" under "Build Settings" to make sure that the framework path is successfully added.

Note: If you are using XCode 12 and above, you may need to go to "Build Settings" -> "Validate Wordspace" and update the flag to be "Yes".

2. Run "strip-frameworks.sh" script.

Switch to "Build Phases" tab, and then add a "Run Script" if it is not present. Then add the line below to the bash script.

bash "${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/DSPhotoEditorSDK.framework/strip-frameworks.sh"

You should see something similar to the screenshot below.

3. Bridging Header

Create a new header (.h) file and add it to our project. Make sure to name this file by your product module name followed by adding "-Bridging-Header.h", such as "DSPhotoEditorSampleSwift-Bridging-Header.h".

Also make sure to specify the name of this header file in the “Objective-C Bridging Header” setting on the Build Settings page as indicated in the screenshot below:

In your bridging header file, import framework umbrella header as below:

#ifndef DSPhotoEditorSampleSwift_Bridging_Header_h
#define DSPhotoEditorSampleSwift_Bridging_Header_h

#import <DSPhotoEditorSDK/DSPhotoEditorSDK.h>

#endif /* DSPhotoEditorSampleSwift_Bridging_Header_h */

4. In your view controller, conform to the "DSPhotoEditorViewControllerDelegate" protocol:

 

class ViewController: DSPhotoEditorViewControllerDelegate

Then launch the DS Photo Editor using the code below. If you don't want some tools to show up, simply pass in an array with TOOL_*** to hide them, otherwise pass in nil for toolsToHide to display all the tools in the SDK.

    /**
     You can pass in an array to hide the tools you don't want:
     let toolsToHide = [TOOL_ORIENTATION, TOOL_PIXELATE]
    **/

    let dsPhotoEditorViewController = DSPhotoEditorViewController(image: image, toolsToHide:nil);
    dsPhotoEditorViewController!.delegate = self

    dsPhotoEditorViewController?.modalPresentationStyle = .fullScreen
    self.present(dsPhotoEditorViewController!, animated: true, completion: nil)

Implement the following methods to receive cancel and complete events from the editor:

 

func dsPhotoEditor(_ editor: DSPhotoEditorViewController!, finishedWith image: UIImage!) {
    self.dismiss(animated: true, completion: nil)

    // handle result image here
}
    
func dsPhotoEditorCanceled(_ editor: DSPhotoEditorViewController!) {
    self.dismiss(animated: true, completion: nil)
}

Important Notes:

1. DS Photo Editor SDK has some tools with transparency processing, such as round corner and circle crop image. Therefore, you need to save png image to see these effects. You can use the code below to save the result image as PNG file:

let pngData = UIImagePNGRepresentation(image)

let pngImage = UIImage(data: pngData!)

UIImageWriteToSavedPhotosAlbum(pngImage!, nil, nil, nil)

2. You may need to update your info.plist file to include "Privacy - Photo Library Usage Description" and "Privacy - Photo Library Additions Usage Description" entries, so that you can load and save photos on devices.

bottom of page