参考
とてもわかりやすい記事
Adobe Creative SDK for ios が本当にやばい
SDKはAdobe IDでログインすれば、無料でDLできます。
https://creativesdk.adobe.com/docs/ios/#/articles/gettingstarted/index.html
上記記事はとてもわかりやすいですが、幾つか困ったので。
frameworkの追加
tbd
従来は.dylibを直接ロードしていましたが、.tbdは、それへの参照を含むファイルのようです。
dylibの代わりとして使えば問題なく使えるはずです。
framework本体の追加
公式ドキュメントでは、bundle等のCopy if neededのフラグは外すよう記述されていましたが、外すとLinkがうまく行かなかったので、僕は外さずにコピーしました。
ダウンロードしたファイル内の
- AdobeCreativeSDKCore.framework/Resources/AdobeCreativeSDKCoreResources.bundle
- AdobeCreativeSDKCore.framework
- AdobeCreativeSDKImage.framework/Resources/AdobeCreativeSDKImageResources.bundle
- AdobeCreativeSDKImage.framework
の4つのファイルを追加します。
他のファイルを追加する場合も、同様にすればokです。
ファイルをプロジェクトに追加すると、リンカなどは自動的に設定されます。(TARGETを選択後、Build PhasesのLink Binary With LibrariesおよびCopy Bundle Resourcesから確認できます)
依存frameworkの追加
それに依存するライブラリは、検索から追加します。TARGETを選択し、Build PhasesのLink Binary With Librariesを開いて、+ボタンからsearchバーでのフィルターしながら、
libz.tbd
libc++.tbd
MobileCoreServices.framework
SystemConfiguration.framework
を追加します。
また、今回使いたいImageEditterには更に追加で必要なフレームワークがあるので、そちらも入れます。Using the Image Editing Componentで確認できる
- Accelerate.framework
- CoreData.framework
- AdobeCreativeSDKImage.framework
- AdobeCreativeSDKFoundation.framework
- libsqlite3.0.dylib
- libz.1.2.5.dylib
- Foundation.framework
- MessageUI.framework
- OpenGLES.framework
- QuartzCore.framework
- StoreKit.framework
- MobileCoreServices.framework
- UIKit.framework
- libc++.dylib
おそらくlibsqlite3.tbdだけでいいかと思います(ある程度デフォルトでリンクされているので)
Objective-Cのframeworkなので
-ObjC
TARGETを選択、Build SettingsのLinkingタブから、Other Linker Flagsに
- -ObjC
- -all_load
を追加
※AdobeCreativeSDKImageを使う場合は、-all_loadも必要になります
参考:Cocoaの日々: [Mac][iOS] Static Library (7) カテゴリを使う場合の注意点 "-ObjC" と "-all_load"
BridgingHeader
New Fileから、Header file(.h)のファイルを作成、名前は今回はAdobeCreativeSDK-Bridging-Header.h
にする。
TARGETを選択、Build Settingsから、
Swift Compiler-Code Generationタブの、
Objective-C Bridging-Headerに
$(PROJECT_DIR)/$(PROJECT_NAME)/AdobeCreativeSDK-Bridging-Header.h
を追加
(ファイルのパスが違う場合は適宜修正)
内容は、
#ifndef AdobeCreative_Bridging_Header_h
#define AdobeCreative_Bridging_Header_h
#import <AdobeCreativeSDKCore/AdobeCreativeSDKCore.h>
#import <AdobeCreativeSDKImage/AdobeCreativeSDKImage.h>
#endif /* AdobeCreative_Bridging_Header_h */
でokです
AppDelegate
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)
に
AdobeUXAuthManager.sharedManager().setAuthenticationParametersWithClientID("*********", clientSecret: "**********-****-****-****-************", enableSignUp: true)
を追記します。
※ enableSignUpがない方はdeprecatedです
呼び出し
import UIKit
class ViewController: UIViewController, AdobeUXImageEditorViewControllerDelegate {
var imageView = UIImageView()
var button = UIButton()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
imageView.frame = self.view.bounds
if !self.view.subviews.contains(imageView) {
self.view.addSubview(imageView)
}
button.frame = CGRectMake(0, 0, 200, 40)
button.layer.position = self.view.center
button.setTitle("edit", forState: .Normal)
button.backgroundColor = UIColor.redColor()
button.addTarget(self, action: "open:", forControlEvents: .TouchUpInside)
if !self.view.subviews.contains(button) {
self.view.addSubview(button)
}
}
func open(sender: UIButton?) {
let adobeViewCtr = AdobeUXImageEditorViewController(image: UIImage(named: "IMG_7724.jpg")!)
adobeViewCtr.delegate = self
self.presentViewController(adobeViewCtr, animated: true) { () -> Void in
}
}
func photoEditor(editor: AdobeUXImageEditorViewController, finishedWithImage image: UIImage?) {
editor.dismissViewControllerAnimated(true, completion: nil)
imageView.image = image
}
func photoEditorCanceled(editor: AdobeUXImageEditorViewController) {
editor.dismissViewControllerAnimated(true, completion: nil)
}
}
メソッドは、Adobe Creative SDK for ios が本当にやばいの方のものそのままです
UIImageは適当に渡せばokです
細かい設定
細かい設定も可能です。参考記事のほうをご参照ください