Bob
Bob

Reputation: 8704

Sinch framework (Objective C) and Swift not compatible

I am using Sinch SDK (link) which is written in Objective C.

But I am making a Swift application. I created bridge header and I added some basic functionality in the view controller:

import UIKit

class ViewController: UIViewController, SINMessageClientDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        initializeSinch()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    func initializeSinch()
    {
        // Instantiate a Sinch client object
        let sinchClient = Sinch.clientWithApplicationKey("xxxxxxxxxxxx", applicationSecret: "xxxxxxxxxx", environmentHost: "sandbox.sinch.com", userId: "user1")
        sinchClient.setSupportMessaging(true)
        sinchClient.start()

        let messageClient = sinchClient.messageClient()

        let message = SINOutgoingMessage(recipient: "user2", text: "Test 123, test 123")
        messageClient.sendMessage(message)
    }

    // Tells the delegate that a message has been received.
    func messageClient(messageClient: SINMessageClient, didReceiveIncomingMessage message: SINMessage) {
        // Present a Local Notification if app is in background
        if UIApplication.sharedApplication().applicationState == .Background {
            var notification: UILocalNotification = UILocalNotification()
            notification.alertBody = "Message from \(message.recipientIds[0])"
            UIApplication.sharedApplication().presentLocalNotificationNow(notification)
        }
        else {
            // Update UI in-app
        }

    }

    // Tells the delegate that a message for a specific recipient has been sent by the local user.
    func messageSent(message: SINMessage, recipientId: String) {
//        var a = 1
    }
//
    // Tells the delegate that a message has been delivered (to a particular recipient).
    func messageDelivered(info: SINMessageDeliveryInfo) {
//        var a = 1
    }

    func messageFailed(message: SINMessage, info messageFailureInfo: SINMessageFailureInfo) {
//        var a = 1
    }

}

This is how the error looks like. Error log

Can someone advice how can I fix this?

Upvotes: 0

Views: 500

Answers (1)

cjensen
cjensen

Reputation: 2703

Have you added all the neccesary frameworks, and the linker flags?

AudioToolbox.framework
AVFoundation.framework
Security.framework

Some additional linker flags need to be added. In the Build Settings pane for the application target, set the following:

Other Linker Flags -> -ObjC -Xlinker -lc++

https://www.sinch.com/docs/voice/ios/

Upvotes: 1

Related Questions