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()

}
user3246092
  • 880
  • 2
  • 13
  • 28
  • Go for NSNotificationObserver. Also see this link http://stackoverflow.com/questions/24049020/nsnotificationcenter-addobserver-in-swift – Bharat Modi Mar 17 '16 at 05:13
  • Your entire strategy is wrong. If you are using a navigation controller, you should navigate to the view. – ryantxr Mar 17 '16 at 05:16

2 Answers2

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.

Jagandeep Singh
  • 364
  • 4
  • 8
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

Pradeep K
  • 3,671
  • 1
  • 11
  • 15