edit: I think it might be about loading .xib from objective-c library and displaying it on swift's view controller
I've been trying to use https://github.com/promet/PRAugmentedReality library in a swift app.
It works perfectly with obj-c, like:
But when i bridge it to swift project it starts to act like this:
Below you can see my steps when i integrated this library to my swift project, codes of my swift project and download link for both objective-c and swift projects. Also here are youtube videos for PR Augmented Reality Framework:
Link 1: Getting Started -> https://www.youtube.com/watch?v=fdN0XAoZXOY
Link 2: Walkthrough of Internals-> https://www.youtube.com/watch?v=Xmx-0OnzTPY
Swift project steps:
Then i imported header files to my bridging file (PRAR.h) like this
#import <PRAR/ARSettings.h>
#import <PRAR/PRARManager.h>
#import <PRAR/ARController.h>
#import <PRAR/ARObject.h>
#import <PRAR/ARRadar.h>
#import <PRAR/LocationMath.h>
Rest of what is did in order to run this framework within my swift project remains in my ViewController.swift file such as:
import UIKit
import PRAR
var prARManager = PRARManager()
let x: Int32 = AR_VIEW_TAG
let y = Int(x)
class ViewController: UIViewController, PRARManagerDelegate{
func alert(title: String, withDetails details: String) {
print("alert function")
let alert: UIAlertView = UIAlertView(title: title, message: details, delegate: nil, cancelButtonTitle: "Ok", otherButtonTitles: "")
alert.show()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
print("1")
// AŞAĞIDAKİ SATIRDA BİR SORUN VAR!!!
prARManager = PRARManager.init(size: self.view.frame.size, delegate: self, showRadar: true)
print("2")
}
override func viewDidAppear(animated: Bool) {
print("3")
let locationCoordinates = CLLocationCoordinate2D(latitude: 41.085468, longitude: 29.044033)
print("4")
prARManager.startARWithData(self.getDummyData() as [AnyObject], forLocation: locationCoordinates)
print("5")
}
func getDummyData() -> NSArray {
print("6")
let dummyData: [AnyObject] = [["id": 0, "lat": 40.9780919, "lon": 27.511674, "title": "Tekirdağ"], ["id": 1, "lat": 40.8025157, "lon": 29.4397941, "title": "Gebze"]]
print("7")
return dummyData;
}
func prarDidSetupAR(arView: UIView, withCameraLayer cameraLayer: AVCaptureVideoPreviewLayer, andRadarView radar: UIView) {
print("8")
NSLog("Finished displaying ARObjects")
print("9")
self.view.layer.addSublayer(cameraLayer)
print("10")
self.view!.addSubview(arView)
print("11")
self.view.bringSubviewToFront(self.view.viewWithTag(y)!)
//self.view.bringSubviewToFront(self.view!.viewWithTag(AR_VIEW_TAG));
//self.view!.bringSubviewToFront(self.view!.viewWithTag( 042313 )!)
//print("12")
self.view.addSubview(radar)
//print("13")
}
func prarUpdateFrame(arViewFrame: CGRect) {
print("14")
self.view.viewWithTag(y)?.frame = arViewFrame
print("hello")
//self.view.viewWithTag(AR_VIEW_TAG)!.frame = arViewFrame
//self.view!.viewWithTag(042313)!.frame = arViewFrame
print("15")
}
func prarGotProblem(problemTitle: String!, withDetails problemDetails: String!) {
print("16")
self.alert(problemTitle, withDetails: problemDetails)
print("17")
}
}
Below you can download the objective-c and swift projects. I just want swift project to be able to run as objective-c project. How can i do that? I'm constantly walking through all framework and my code but i cannot see something wrong. *ps: I'm using Xcode version 7.2.1
Swift project's link: https://drive.google.com/file/d/0B-cDfWHidgvcYnFNcnlMZG1aaDg/view?usp=sharing
Objective-C project's link: https://drive.google.com/file/d/0B-cDfWHidgvcQUFXbktYSE5CeHM/view?usp=sharing
You can use Objective-C and Swift files together in a single project, no matter which language the project used originally. This makes creating mixed-language app and framework targets as straightforward as creating an app or framework target written in a single language.
Support Objective-C pods in a Swift project First, create your Podfile and add the pods you need as usual. Install them using the pod install command and open the . xcworkspace file created in your project folder. Pods should now be included in your workspace.
The correct approach is as follows: Import your Objective C framework by dragging and dropping the framework into an Xcode 6 Swift project. Create a new Objective C file in your project (File->New->File [Objective C for iOS]). Accept the prompt (agree) to create a bridging header file between Objective C and Swift.
While Objective-C is still supported by Apple and will likely not be deprecated anytime soon, there will be no updates to the language.
You forgot to add framework resources to you Swift project, see the Obj-C project:
compared to Swift project:
Make sure all the necessary images and xibs have target membership in "demoAR":
If you look at your Obj-C project, you'll see the image files (like RadarMV.png) are assigned to the app target. But in the Swift project, they're assigned to the PRAR target. So the app just isn't finding the images it's trying to load.
You could modify the code to find the images in the PRAR bundle. But a quicker solution (maybe not better) is to just assign the images to the app target:
This was enough to get things working for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With