ios - iOS9 error on activityManager.startActivityUpdatesToQueue -


i opened app in new xcode7 beta worked fine in older version. i'm receiving errors, , don't know how solve it. here code. error commented out.

import uikit import coremotion class viewcontroller: uiviewcontroller {  let activitymanager = cmmotionactivitymanager() let pedometer = cmpedometer()  @iboutlet weak var activitystate: uilabel!  override func viewdidload() {     super.viewdidload()     // additional setup after loading view, typically nib.      if(cmmotionactivitymanager.isactivityavailable()){         print("yess!")         self.activitymanager.startactivityupdatestoqueue(nsoperationqueue.mainqueue(), withhandler: {(data: cmmotionactivity!) -> void in  //cannot invoke 'startactivityupdatestoqueue' argument list of type '(nsoperationqueue, withhandler: (cmmotionactivity!) -> void)'         dispatch_async(dispatch_get_main_queue(), {() -> void in           if(data.stationary == true){         self.activitystate.text = "stationary"         } else if (data.walking == true){         self.activitystate.text = "walking"         } else if (data.running == true){         self.activitystate.text = "running"         } else if (data.automotive == true){         self.activitystate.text = "automotive"         }          })         }) }  }  override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }   } 

the problem data type cmmotionactivity? not cmmotionactivity!

here should work you:

 if(cmmotionactivitymanager.isactivityavailable()){         print("yes!")         self.activitymanager.startactivityupdatestoqueue(nsoperationqueue.mainqueue()) { data in             if let data = data {                 dispatch_async(dispatch_get_main_queue()) {                     if(data.stationary == true){                         self.activitystate.text = "stationary"                     } else if (data.walking == true){                         self.activitystate.text = "walking"                     } else if (data.running == true){                         self.activitystate.text = "running"                     } else if (data.automotive == true){                         self.activitystate.text = "automotive"                     }                 }             }         }     } 

also try take advantage of last argument closure simplify function calls.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -