• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Swift iOS ANE Framework

Participant ,
Aug 27, 2015 Aug 27, 2015

Copy link to clipboard

Copied

Hey,

Has anybody played with making an iOS ANE using swift?

When using Swift, you can't make a Static Library (.a file). You have to make a framework instead. So in the extension.xml, instead of pointing to a .a file, I'm going to point to the .framework instead.

I'm about to finish up packaging up the ANE to see if this works or not. If anybody have experience in this, share you experience. Thanks.

TOPICS
Development

Views

6.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 02, 2017 Mar 02, 2017

Copy link to clipboard

Copied

That's outstanding to hear!

I have a question, if I write 8 custom functions in my Swift Class, each function takes parameters input from AS3 side, now in order to do this, do I have to write 8 corresponding functions in the OC bridge (so that AS3 calls OC, OC calls Swift), or do I just need to write only one function in the OC bridge, that function takes 3 parameters: swiftClassName (which is a String), swiftFunctionName (which is a String) and swiftFunctionParameters (which is an Array), so that AS3 calls OC, then the OC function calls Swift and deliver the parameters?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 05, 2017 Mar 05, 2017

Copy link to clipboard

Copied

Updated repo with latest code.

Now allows calls to FRE functions from Swift

The project contains a translation of FlashRuntimeExtensions to Swift. It is comprised of 2 parts.

  1. A static library which exposes methods to AIR and a thin ObjectiveC API layer to the Swift code.
  2. A dynamic Swift Framework which contains the main logic of the ANE.

To allow FRE functions to be called from within Swift, a protocol acting as a bridge back to Objective C was used.

Example - Converting a FREObject into a String

var swiftString: String = ""

var len: UInt32 = 0

let status: FREResult = FREGetObjectAsUTF8(object: object, length: &len, value: &swiftString)

var airString: FREObject? = nil

let status: FREResult = FRENewObjectFromUTF8(length: UInt32(string.utf8.count), value: ret, object: &freObject)

Example - Converting a FREObject into a String the easy way, using ANEHelper.swift

let swiftString: String = aneHelper.getString(object: object)

let airString: FREObject? = aneHelper.getFREObject(string: swiftString)

trace(value: swiftString)

GitHub - tuarua/SwiftIOSANE: Example Air Native Extension written in Swift 3 for iOS 10

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 01, 2017 Jun 01, 2017

Copy link to clipboard

Copied

Thanks for documenting all your work and providing the project setups on github.

Following your techniques, I was also able to integrate a third-party Swift framework into an ANE project and get it to work on iOS, tvOS and macOS.

Quite a bit of fidgeting, and as you mention with your tools, requires resigning .ipa before using on iOS and tvOS devices.

Given that more and more third party frameworks are switching to Swift instead of Objective-C, it is becoming limiting to assume we are going to be able to build all our ANEs with static libs.

I second the idea that Adobe should devote some resources to making Swift framework integration into ANE development the new norm for iOS/tvOS/macOS platforms.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 01, 2017 Jun 01, 2017

Copy link to clipboard

Copied

Hi jadams602,

Thanks for the thanks!

I'm really glad to hear someone is using the Swift port of FRE for building real ANEs and it is not sitting as a POC.

Also the fact that it works for tvOS is welcome news. I often wondered.

The code has changed a fair bit from when I first started, as I learned from doing a C# wrapper also.

I think I am done with any major structural changes.

The next thing I am working on is adding helpers for the concept of a "Native Stage". One major drawback of adding a native control, say a webview, is that you then lose the ability place flash objects above the native element. Wouldn't it be nice to be able to add graphics or buttons directly from the actionscript side!!

I can't officially say that Adobe are working on Swift integration for ANEs but am eager to see what it may bring. It may turn out all my work becomes obsolete. haha. Shall see.

Whatever comes, yes the resigning integration is important, given some devs are reluctant to have to worry about bash scripts and such.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 01, 2017 Jun 01, 2017

Copy link to clipboard

Copied

I think the best solution is to have the IDE do the tedious stuff like resigning for us. FlashBuilder CC? lol

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 02, 2017 Jun 02, 2017

Copy link to clipboard

Copied

Actually, having re-read your post you may be saying that you integrated a Swift framework into an existing Obj C based ANE rather than using FreSwift?

Either way good you were able to follow the same techniques.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 05, 2017 Mar 05, 2017

Copy link to clipboard

Copied

You don't have to write 8 matching functions in ObjC. You could use a single ObjC function which acts as a 'switch'. You could then call the Swift methods using SelectorString.

However, it's not considered good practice. For eg, Each Swift method would have to take and return parameters. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 07, 2017 Mar 07, 2017

Copy link to clipboard

Copied

Awesome!

One more question, when people using your solution (which is now availbe on your GitHub), is it possible for them to only write the Swift codes, and don't have to write the OC codes at all? If so, that will be outstanding!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 07, 2017 Mar 07, 2017

Copy link to clipboard

Copied

beggars can't be choosers

DEFINITION

proverb

people with no other options must be content with what is offered.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Aug 04, 2017 Aug 04, 2017

Copy link to clipboard

Copied

jadams602​ and I have been testing AIR 27 Beta with regards to the signing of AIR apps which include Swift Dynamic frameworks.

There is now no need for workaround tools or resigning scripts to run on an iOS device.

An issue with using Simulator may need to be resolved, but AIR 26 can be used for this.

Adobe notes:

1. You need to keep external Frameworks inside <Root_IPA_PATH>/Frameworks folder to be signed by ADT. Otherwise external framework files will be ingnored for signing.

2. Frameworks folder contains External Framework library as well as Swift dylib dependencies if any.

3. Reference Packaging command for Sample IPA with external framework:

- Using command line:

bin/adt -package -target ipa-app-store -provisioning-profile <Path_To_ProvisiongProfile> -storetype pkcs12 -keystore <Path_To_Certificate> -storepass <Password> new.ipa SwiftSampleiOS-app.xml SwiftSampleiOS.swf Frameworks -extdir .

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 09, 2017 Nov 09, 2017

Copy link to clipboard

Copied

For anyone interested.

I put together a short video tutorial showing the steps to create a Hello World ANE using Swift

SwiftANE- Hello World Example Part 1 - YouTube

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 07, 2018 Feb 07, 2018

Copy link to clipboard

Copied

Hello el111

Thanks for such a great FRE swift framework that you put on GitHub.  Now, when adobe has released AIR 28, which supports swift and signing dynamic frameworks, is it helpful to write an ANE without using your FRE framework? 

I have seen all three of your videos on ANEs using swift.  I used your framework and started an ANE. I am using storyboards. 

I am stuck at how can I perform a segue operation to launch a storyboard from SwiftController class. I will appreciate if you could

give me your valuable suggestions or guidance towards right direction.

Thanks.

Warm regards.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 07, 2018 Feb 07, 2018

Copy link to clipboard

Copied

FreSwift makes things a lot easier. It is much more complicated to write a Swift based ANE without it.

With FreSwift:

var myString = String(argv[0])

Without FreSwift:

var myString = ""

var len: UInt32 = 0

var valuePtr: UnsafePointer<UInt8>?

let status: FREResult = FREGetObjectAsUTF8(argv[0], &len, &valuePtr)

if FRE_OK == status {

   myString = (NSString(bytes: valuePtr!, length: Int(len), encoding: String.Encoding.utf8.rawValue) as String?)!

}

Storyboards

You need to package the storyboard with your AIR app.

1) Add a new Target of type Cocoa Touch Framework called "Storyboards"

2) Add new Storyboard (Copy Bundle Resources)

3) Build the framework

4) copy Build/Products/Release-iphoneos/StoryBoards.framework/Main.storyboardc to example/ios_dependencies/device

And to reference the viewController in your ANE

// loads Main.storyboardc

let storyboard = UIStoryboard(name: "Main", bundle: nil)

// get UIViewController with id "viewController"

let vc = storyboard.instantiateViewController(withIdentifier: "viewController")

// get AIR view controller

if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {

    // present vewController from storyboard

    rootViewController.present(vc, animated: true, completion: nil)

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 19, 2018 Feb 19, 2018

Copy link to clipboard

Copied

Hello,

Thanks for your valuable suggestions. I followed your guidelines and I was able to compile and test it on simulator. However, when I wanted to deploy on device, it's failing with error: ApplicationVerificationFailed. I looked for the messages in console. I found that "atc" is complaining that "Storyboards.framework" have different signature. Very strange, because in xcode, no signing information is specified. It's only animate cc (or) Intellij ide who is buiding and trying to install. I got same error with both animate cc and Intellij IDEA. I am using AIR SDK 28. 

However, if I re-sign the ipa using bash script, it gets installed and runs correctly.

In your reply earlier, you did not tell to copy the "Storyboards.framework". Is it required or not. only copying Main.storyboard is sufficient?

Thanks in advance.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 19, 2018 Feb 19, 2018

Copy link to clipboard

Copied

Storyboards.framework is just an easy way of generating the Main.storyboardc file (note the c for "compiled")

You should not package the Storyboards.framework, just Main.storyboardc

I am sure I tested this on a real device and had no signing issues - running from IntelliJ.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 20, 2018 Feb 20, 2018

Copy link to clipboard

Copied

LATEST

Hi,

Yes, you are correct. It compiled and got installed without any errors, if I don't add Storybaords.framework in the ANE and in the IPA.  But, I wonder what's the problem if we add that framework also? Installd (daemon) is complaining exactly about that framework only, that it has different signature. Can you please comment on this, help us understand better.

Thanks in advance.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines