Friday, 25 February 2011

Working in Simulator but not on device


i trying run program on iphone 3gs ios 5. program works fine on simulator doesn't work on device. no error locationmanager:didupdatetolocation:fromlocation delegate method doesn't called when run on device.

want print location after every 30 seconds.

code:
 int main(int argc, char *argv[]) {     ilocation *loc = [[ilocation alloc] init];       nsdate *now = [[nsdate alloc] init];      nstimer *timer = [[nstimer alloc] initwithfiredate:now                                                interval:30                                                  target:loc                                                selector:@selector(start)                                                userinfo:nil                                                 repeats:yes];       nsrunloop *runloop = [nsrunloop currentrunloop];     [runloop addtimer:timer formode:nsdefaultrunloopmode];     [runloop run]; }   @interface ilocation : nsobject <cllocationmanagerdelegate>  @property (strong, nonatomic) cllocationmanager *locationmanager; @property (strong, nonatomic) nstimer *timer;   -(void) start;  @end   @implementation ilocation  @synthesize locationmanager; @synthesize timer;    -(void) start {     nslog(@"enter in start");      locationmanager = [[cllocationmanager alloc] init];     locationmanager.delegate = self;          locationmanager.desiredaccuracy = kcllocationaccuracybest;          [locationmanager startupdatinglocation];      nslog(@"exit start");  }    #pragma mark - #pragma mark cllocationmanagerdelegate methods - (void)locationmanager:(cllocationmanager *)manager     didupdatetolocation:(cllocation *)newlocation            fromlocation:(cllocation *)oldlocation  {     nslog(@"enter in didupdatetolocation");      /*if (startingpoint == nil)      self.startingpoint = newlocation;*/      nsstring *latitudestring = [nsstring stringwithformat:@"%g\u00b0",                                 newlocation.coordinate.latitude];     //latitudelabel.text = latitudestring;     nslog(@"latitude = %@", latitudestring);       nsstring *longitudestring = [nsstring stringwithformat:@"%g\u00b0",                                  newlocation.coordinate.longitude];     //longitudelabel.text = longitudestring;     nslog(@"longitude = %@", longitudestring);       nsstring *horizontalaccuracystring = [nsstring stringwithformat:@"%gm",                                           newlocation.horizontalaccuracy];     //horizontalaccuracylabel.text = horizontalaccuracystring;     nslog(@"horizontal accuracy = %@", horizontalaccuracystring);       nsstring *altitudestring = [nsstring stringwithformat:@"%gm",                                 newlocation.altitude];     //altitudelabel.text = altitudestring;     nslog(@"altitude = %@", altitudestring);       nsstring *verticalaccuracystring = [nsstring stringwithformat:@"%gm",                                         newlocation.verticalaccuracy];     //verticalaccuracylabel.text = verticalaccuracystring;     nslog(@"vertical accuracy = %@", verticalaccuracystring);        [locationmanager stopupdatinglocation];       nslog(@"exit didupdatetolocation"); }    - (void)locationmanager:(cllocationmanager *)manager        didfailwitherror:(nserror *)error {     nslog(@"enter in didfailwitherror");      nsstring *errortype = (error.code == kclerrordenied) ?     @"access denied" : @"unknown error";      nslog(@"%@", errortype);      nslog(@"exit didfailwitherror"); }  @end
 

how long trying for? inside?

sitting, have had success getting coordinates quickly?

thing is, gps pretty rubbish, if sitting inside computer may not able communicate satellites. takes bit of time coordinates, more 30 sec.

load app , go outside bit. create viewcontroller can post logging can see going on.
 


Forums iPhone, iPad, and iPod Touch iOS Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

No comments:

Post a Comment