Code Monkey home page Code Monkey logo

swift-ios-ane's Introduction

FreSwift

Example Xcode projects showing how to create AIR Native Extensions for iOS, tvOS & macOS using Swift.
It supports iOS 11.0+, tvOS 11.1+, macOS 10.13+

Xcode 14.2 (14C18) must be used with Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)

It is not possible to mix Swift versions in the same app. Therefore all Swift based ANEs must use the same exact version.

This project is used as the basis for the following ANEs
Firebase-ANE
Vibration-ANE
GoogleMaps-ANE
AdMob-ANE
WebViewANE
AR-ANE
ML-ANE


paypal

Getting Started

A basic Hello World starter project is included for each target

How to use

Full documentation is provided

The following table shows the primitive as3 types which can easily be converted to/from Swift types

AS3 type Swift type AS3 param->Swift return Swift->AS3
String String let str = String(argv[0]) return str.toFREObject()
int Int let i = Int(argv[0]) return i.toFREObject()
Boolean Bool let b = Bool(argv[0]) return b.toFREObject()
Number Double let dbl = Double(argv[0]) return dbl.toFREObject()
Number CGFloat let cfl = CGFloat(argv[0]) return cfl.toFREObject()
Date Date let date = Date(argv[0]) return date.toFREObject()
Rectangle CGRect let rect = CGRect(argv[0]) return rect.toFREObject()
Point CGPoint let pnt = CGPoint(argv[0]) return pnt.toFREObject()
Vector int [Int] let a = [Int](argv[0]) return a.toFREObject()
Vector Boolean [Bool] let a = [Bool](argv[0]) return a.toFREObject()
Vector Number [Double] let a = [Double](argv[0]) return a.toFREObject()
Vector String [String] let a = [String](argv[0]) return a.toFREObject()
Object [String, Any]? let dct = Dictionary.init(argv[0]) N/A
null nil return nil

Basic Types

let myString: String? = String(argv[0])
let myInt = Int(argv[1])
let myBool = Bool(argv[2])

let swiftString = "I am a string from Swift"
return swiftString.toFREObject()

Creating new FREObjects

let newPerson = FREObject(className: "com.tuarua.Person")

// create a FREObject passing args
// 
// The following param types are allowed: 
// String, Int, UInt, Double, Float, CGFloat, NSNumber, Bool, Date, CGRect, CGPoint, FREObject
let frePerson = FREObject(className: "com.tuarua.Person", args: "Bob", "Doe", 28, myFREObject)

Calling Methods

// call a FREObject method passing args
// 
// The following param types are allowed: 
// String, Int, UInt, Double, Float, CGFloat, NSNumber, Bool, Date, CGRect, CGPoint, FREObject
let addition = freCalculator.call(method: "add", args: 100, 31) {

Getting / Setting Properties

let oldAge = Int(person["age"])
let newAge = oldAge + 10

// Set property using braces access
person["age"] = (oldAge + 10).toFREObject()

// Create using FreObjectSwift allowing us to get/set properties using inferred types
// The following param types are allowed: 
// String, Int, UInt, Double, Float, CGFloat, NSNumber, Bool, Date, CGRect, CGPoint, FREObject
if let swiftPerson = FreObjectSwift(className: "com.tuarua.Person") {
    let oldAge:Int = swiftPerson.age
    swiftPerson.age = oldAge + 5
}

Arrays

let airArray: FREArray = FREArray(argv[0])
// convert to a Swift [String]
let airStringVector = [String](argv[0])

// create a Vector.<com.tuarua.Person> with fixed length of 5
let myVector = FREArray(className: "com.tuarua.Person", length: 5, fixed: true)
let airArrayLen = airArray.length

// loop over FREArray
for fre in airArray {
    trace(Int(fre))
}

// set element 0 to 123
airArray[0] = 123

// push 2 elements to a FREArray
airArray.push(66, 77)

// return Int Array to AIR
let swiftArr: [Int] = [99, 98, 92, 97, 95]
return swiftArr.toFREObject()

Sending Events back to AIR

trace("Hi", "There")

// with interpolation
trace("My name is: \(name)")

dispatchEvent("MY_EVENT", "this is a test")

Bitmapdata

if let img = UIImage(freObject: argv[0]) {
    if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {
        let imgView: UIImageView = UIImageView(image: img)
        imgView.frame = CGRect(x: 0, y: 0, width: img.size.width, height: img.size.height)
        rootViewController.view.addSubview(imgView)
    }
}

ByteArrays

let asByteArray = FreByteArraySwift(freByteArray: argv[0])
if let byteData = asByteArray.value { // NSData
	let base64Encoded = byteData.base64EncodedString(options: .lineLength64Characters)
}

Error Handling

FreSwiftLogger.shared.context = context

guard FreObjectTypeSwift.int == expectInt.type else {
    return FreError(stackTrace: "",
        message: "Oops, we expected the FREObject to be passed as an int but it's not",
        type: .typeMismatch).getError(#file, #line, #column)
}

Advanced Example - Extending. Convert to/from SCNVector3

public extension SCNVector3 {
    init?(_ freObject: FREObject?) {
        guard let rv = freObject else { return nil }
        let fre = FreObjectSwift(rv)
        self.init(fre.x as CGFloat, fre.y, fre.z)
    }
    func toFREObject() -> FREObject? {
        return FREObject(className: "flash.geom.Vector3D", args: x, y, z)
    }
}

public extension FreObjectSwift {
    public subscript(dynamicMember name: String) -> SCNVector3? {
        get { return SCNVector3(rawValue?[name]) }
        set { rawValue?[name] = newValue?.toFREObject() }
    }
}

applicationDidFinishLaunching

The static library contains a predefined +(void)load method in FreMacros.h. This method can safely be declared in different ANEs. It is also called once for each ANE and very early in the launch cycle. In here the SwiftController is inited and onLoad() called. This makes an ideal place to add observers for applicationDidFinishLaunching and any other calls which would normally be added as app delegates, thus removing the restriction of one ANE declaring itself as the "owner".
Note: We have no FREContext yet so calls such as trace, dispatchEvent will not work.

@objc func applicationDidFinishLaunching(_ notification: Notification) {
   appDidFinishLaunchingNotif = notification //save the notification for later
}
func onLoad() {
    NotificationCenter.default.addObserver(self, selector: #selector(applicationDidFinishLaunching),
    name: UIApplication.didFinishLaunchingNotification, object: nil)    
}

Required AS3 classes

com.tuarua.fre.ANEUtils.as and com.tuarua.fre.ANEError.as and avmplus.DescribeTypeJSON are required by FreSwift and should be included in the AS3 library of your ANE

Prerequisites

You will need

  • Xcode
  • IntelliJ IDEA
  • AIR 50.1+
  • wget on macOS via brew install wget
  • Carthage

swift-ios-ane's People

Contributors

tuarua avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift-ios-ane's Issues

ERROR ITMS-90075 verify distribution build via app store

After I added 'ios_dependencies/device' to my build, I can not upload the build to the appstore. the application loader produces this error:

ERROR ITMS-90075: "This bundle is invalid. The application-identifier entitlement is missing; it should contain your 10-character Apple Developer ID, followed by a dot, followed by your bundle identifier."

Without ios_dependencies build uploaded normally but for obvious reasons it does not launch.
Signing code is disabled in all targets in the xcode

i use air sdk 30, ios sdk 11.4, xcode 9.4. all other settings as in the tutorial

App Crashes on the device.

I am very sorry my english was poor.
I have install those software to my macOS Mojave 10.14.2
Xcode 10.1 (10B61)
IntelliJ IDEA
AIR 32
and Copy the files from AIRSDK_patch into the corresponding folders in my AIR SDK.

I install Hello World starter project to my iphone6plus(10.3.1)
when I click the app,it crash.

last year I have success run the Hello World starter project in my iphone.

code signature invalid for libswiftCore.dylib on ios 10.2

Using FreSwift 4.1.0, Xcode 11.2.1 and Air 32, I got this error on ios 10.2.1 and ios 11 devices:

DYLD, Library not loaded: @rpath/libswiftCore.dylib | Referenced from: /private/var/containers/Bundle/Application/CEEBD220-AF50-480B-9DFE-73B287B2DAC3/ParentsApp.app/Frameworks/FreSwift.framework/FreSwift | Reason: no suitable image found. Did find: | /private/var/containers/Bundle/Application/CEEBD220-AF50-480B-9DFE-73B287B2DAC3/ParentsApp.app/Frameworks/libswiftCore.dylib: code signature invalid for '/private/var/containers/Bundle/Application/CEEBD220-AF50-480B-9DFE-73B287B2DAC3/ParentsApp.app/Frameworks/libswiftCore.dylib' | | /private/var/containers/Bundle/Application/CEEBD220-AF50-480B-9DFE-73B287B2DAC3/ParentsApp.app/Frameworks/libswiftCore.dylib: code signature invalid for '/private/var/containers/Bundle/Application/CEEBD220-AF50-480B-9DFE-73B287B2DAC3/ParentsApp.app/Frameworks/libswiftCore.dylib'

It works on ios 13.3.1. Is the error related to using Air 32?

Widget ANE

Hi!
Is it possible to create a widget ANE?
Maybe a "Hello world" example?

Thanks!

code signature invalid for libswiftCore.dylib

Hi, I've been trying to deploy the example on a real device but I keep getting this error.

Termination Description: DYLD, Library not loaded: @rpath/libswiftCore.dylib | Referenced from: /private/var/containers/Bundle/Application/29989E08-4277-406A-BD19-A58427931869/HelloMofilerExample.app/Frameworks/FreSwift.framework/FreSwift
.........
code signature invalid for '/private/var/containers/Bundle/Application/29989E08-4277-406A-BD19-A58427931869/HelloMofilerExample.app/Frameworks/libswiftCore.dylib'
.......

I know I should be using xcode 9.4.1 and I'm on 10.1. But I'm not sure this could be related to that.

Any help will be much appreciate it!

Basic Question about compiling

I'm not able to compile the XCode project, i changed the build settings to reflect my account, but as not much info / tutorials are available.
So, if any time u get a chance to make a video/tutorial about this, it would be amazing... I definitly want to get my hands dirty on Swift/AIR

tvOS ANE strange error

Hello,

I tried to testing the ANE but ADT return on macOS :

ld: library not found for -lclang_rt.ios
Compilation failed while executing : ld64

I don't unserstand this message, the library must be -lclang_rt.tvos and not -lclang_rt.ios,
and it's missing in <AIR_SDK>/lib/aot/lib-tvos

on Windows the compilation work but when I start the ANE on Apple TV Xcode Console return :

VerifyError: Error #1014: Class flash.external::ExtensionContext could not be found.

I use :
adt -package -target ipa-test...
and

<key>UIDeviceFamily</key>
<array>
    <string>3</string>
</array>

Thanks.

Anyway to cut down the size of ios dependencies frameworks?

Hello, thanks for your great work first, I'm trying to follow them and learning, and I'm a new Swift Learner. Is there any way to cut down the size of ios dependencies frameworks? I test with your Vibration ANE example, and the IPA size goes to 42M, I use the old Admob ANE with Objective-c written test project, an empty project IPA only take less than 20M. Was adding all these huge 'dylib' necessary?

image

Support for iOS 11

I've been struggling with XCode 9.0/iOS 11 - and I just noticed your commit about XCode 9 not being supported, so just wanted to check with you about my experience so far and share one solution to a problem I had including iOS 11.

I ran into an issue including iOS 11 in my main project - this was solved here:
https://forums.adobe.com/thread/2382667

I was able to build the ANE and I'm targeting iOS 10 - however the error I'm seeing when including the ANE in my project is this:

ld: embedded dylibs/frameworks are only supported on iOS 8.0 and later (@rpath/FreSwift.framework/FreSwift) for architecture arm64
ld: embedded dylibs/frameworks are only supported on iOS 8.0 and later (@rpath/FreSwift.framework/FreSwift) for architecture armv7
Compilation failed while executing : ld64

Is this one of the reasons that XCode 9 is not supported or is this something that you might know how to resolve?

This project rocks btw, love the idea of being able to use Swift! Thank you for sharing.

Error linking applications on Windows and Mac with older XCode (e.g. 10)

You receive linking errors while packaging applications with provided swift stubs (text-based tbd-s).

The reason is ld64 from AIR SDK does not support tbd version 4 (that format used currently in AIRSDK_Additions). It is possible to use another version of tbd format. I found that version 1 and 2 are supported.

Also, some symbols are different on iphoneos and iphonesimulator platforms. Fortunately, you can list all that symbols in one file for different architectures.

Here are swift 5.0 stubs for iphoneos and iphonesumulator merged into v1 tbds:

stub.zip

native_extension/ane/build_xxx.sh script searches in wrong location

The ANE build scripts, "native_extension/ane/build_xxx.sh", refers to location in Project_dir/Build/Platforms/... folders, where as, xcode 9.4.1 stores build files not in project folder. Can you explain what needs to be done to make your build_ios.sh script work without errors?
UPDATING VIDEOS ON YOUTUBE REALLY HELPS USERS!
Thank you.

Support for iOS 12, Xcode 10, Swift 4.2

Support for iOS 12 will be added when AIR gets built with iOS SDK 12.
Although iOS 12 + Xcode 10 is due for release in late September, going by last year AIR 32 will be built with SDK 12.
Beta in mid November with release in December.

  • Upgrade to Xcode 10.1
  • Upgrade to iOS SDK 12.1
  • Upgrade to Swift version 4.2.1 (swiftlang-1000.11.42 clang-1000.11.45.1)
  • Upgraded to AIR SDK 32
  • Add FREArray.push()
  • Add FREArray.insert()
  • Add FREArray.remove()
  • Add FREArray.isEmpty
  • Add FREObject.hasOwnProperty()
  • Add FREObject.toString()
  • Add @dynamicMemberLookup to FreObjectSwift. Adds cleaner way to extend FREObjects
  • Mark FREObject.call() as @discardableResult
  • Remove try catches and make better use of optionals
  • Remove ArgCountError class
  • Obsoleted sendEvent() method
  • Deprecate FREObject.setProp() - use accessor or FreSwiftObject wrapper instead
  • Deprecate FREObject.getProp() - use accessor or FreSwiftObject wrapper instead
  • FreSwiftMainController.TAG is now public static var String
  • UIColor / NSColor changed to single convenience init()
  • Add FreSwiftLogger to trace any FREExceptions
  • FREObject.init() to return optional and not require try
  • CommonDependancies.ane renamed to FreSwift.ane
  • Refactoring

Development underway in branch
https://github.com/tuarua/Swift-IOS-ANE/tree/3.0.0

tvOS version - Register your interest here. (in BETA)

FreSwift is available for both iOS and OSX.
I am looking to also bring it to tvOS to complete the triumvirate but will need to first gauge how many people want a tvOS version.
Secondly, I would need it to be funded (mostly to cover the costs of an AppleTV device)
FreSwift for all it's awesomeness has received 0 donations.

Application Loader upload my ipa - WARNING ITMS-90722: "Certificate Expired.

sorry,my english is poor
I have develop two app with one ane,
the first ipa ,Application Loader upload is ok,
the second ipa, Application Loader upload is error, this is the error message:

WARNING ITMS-90722: "Certificate Expired. The signing certificate "CN=Apple Worldwide Developer Relations Certification Authority, OU=Apple Worldwide Developer Relations, O=Apple Inc., C=US" with serial number 25 used to sign meeting.app/Frameworks/FreSwift.framework has expired. Learn more (https://help.apple.com/xcode/mac/current/#/dev154b28f09)."

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.