promet / PRAugmentedReality

iOS Augmented Reality Framework
http://praugmentedreality.com/
MIT License
606 stars 162 forks source link

Radar images and AR pinpoint on camera view doesn't show up with Swift #55

Closed TimurAykutYildirim closed 7 years ago

TimurAykutYildirim commented 8 years ago

It works perfectly with obj-c, like: http://i.stack.imgur.com/wN3Q7.jpg But when i bridge it to swift project it starts to act like this: http://i.stack.imgur.com/zlBfp.jpg

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.

  1. Creating a single view application with Xcode Version 7.2.1 (7C1002) named demoAR
  2. I add Foundation.framework, CoreGraphics.framework and UIKit.framework from Targets -> demoAR -> Build Phases -> Link Binary with Libraries
  3. Then, File -> New Target -> Cocoa Touch Framework and clicked Next
  4. Created a Target which has these properties: Product Name: PRAR , Language: Objective-C and Organization Identifier: com.timur.PRAR then I clicked Finish Screenshot: http://i.stack.imgur.com/1d4Sc.png
  5. I created another group under PRAR and named it as "Classes", Then i copied files from Classes folder of framework and added them to PRAR/Classes folder.
  6. I changed each .h files of framework's Target Membership to "Public" Screenshot: http://i.stack.imgur.com/sAvvY.jpg
  7. 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>

8.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")
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
        print("20")
    }
}

You may download my;

swift project : https://drive.google.com/file/d/0B-cDfWHidgvcYnFNcnlMZG1aaDg/view?usp=sharing objective-c project : https://drive.google.com/file/d/0B-cDfWHidgvcQUFXbktYSE5CeHM/view?usp=sharing

TimurAykutYildirim commented 8 years ago

Turns out I just forgot to add framework's resources to my swift project. link