0

I am making an app that uses iBeacon. When the iBeacon is detected (inside AppDelegate), the app detects the phone's coordinates and forwards them to an API.

I have a function called runGPS() set up in ViewController which does the above and am trying to get it to execute when the iBeacon is detected.

When I do ViewController().runGPS(), I get an error: Missing parameter for 'coder' in call

I've looked up this issue and keep going around in circles on resolving it. One correction leads to another error etc. etc. etc.

How does one correct this or is my overall strategy for this wrong?

func locationManager(manager: CLLocationManager,
    didEnterRegion region: CLRegion) {
        manager.startRangingBeaconsInRegion(region as! CLBeaconRegion)
        manager.startUpdatingLocation()

        NSLog("You entered the region")

        ViewController(NSCoder)!.runGPS()

}
2
  • Go for NSNotificationObserver. Also see this link stackoverflow.com/questions/24049020/… Commented Mar 17, 2016 at 5:13
  • Your entire strategy is wrong. If you are using a navigation controller, you should navigate to the view. Commented Mar 17, 2016 at 5:16

2 Answers 2

2

I have also implemented iBeacon in my application. You have to add this location manager delegate in that viewcontroller and set delegate there like

locationManager.delegate = self
locationManager.requestAlwaysAuthorization()

and you can check in viewController if any user enter to your beacon region then this delegate method will run

 func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {

    }

you can check your beacon in beacons array received in parameter.

Sign up to request clarification or add additional context in comments.

Comments

1

You should separate out the runGPS() code from the ViewController class if its not meant to be there. Is it using any of the ViewController's functionality? If not then you should move it to a separate class meant for passing data to API. If you cannot do that then you can declare runGPS as a static method and called ViewController.runGPS() provided you are not using any of the properties of the ViewController in runGPS() method

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.