Swift如何使用Affdex SDK?

How to use Affdex SDK in Swift?

我们正在尝试使用带有桥接头的 iOS Affdex SDK(在 Swift 中)。您能否帮助我们如何进行此过程。另外,我们如何基于 SDK 显示表情符号(agin 使用 Swift)。

这里有一些链接可以帮助您使用 Objective-C 到 Swift 命名约定:

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html

我附上了一个简单的视图控制器 class,它展示了如何在 Swift 中使用我们的 SDK。希望这对你有所帮助。

    class ViewController: UIViewController, AFDXDetectorDelegate {

    var detector : AFDXDetector? = nil

    override func viewDidLoad() {
        super.viewDidLoad()

        // create the detector
        detector = AFDXDetector(delegate:self, usingCamera:AFDX_CAMERA_FRONT, maximumFaces:1)
        detector?.setDetectEmojis(true)
        detector!.start()
    }

    func detectorDidStartDetectingFace(face : AFDXFace) {
        // handle new face
    }

    func detectorDidStopDetectingFace(face : AFDXFace) {
        // handle loss of existing face
    }

    func detector(detector : AFDXDetector, hasResults : NSMutableDictionary?, forImage : UIImage, atTime : NSTimeInterval) {
        // handle processed and unprocessed images here
        if hasResults != nil {
            // handle processed image in this block of code

            // enumrate the dictionary of faces
            for (_, face) in hasResults! {
                // for each face, get the rage score and print it
                let emoji : AFDXEmoji = face.emojis
                let rageScore = emoji.rage
                print(rageScore)
            }                
        } else {
            // handle unprocessed image in this block of code
        }
    }