Submit location information to a separate service from iPhone? -
is possible send info location of iphone separate service, though application running in background or background service?
you need phone call webservice in cllocationmanagerdelegate method see e.g. below
- (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation { cllocationcoordinate2d coordinate = [newlocation coordinate]; cllocationcoordinate2d oldcoordinate = [oldlocation coordinate]; cllocation *newlocation = [[cllocation alloc] initwithlatitude:coordinate.latitude longitude:coordinate.longitude]; cllocation *oldlocation = [[cllocation alloc] initwithlatitude:oldcoordinate.latitude longitude:oldcoordinate.longitude]; latitude =coordinate.latitude; longitude =coordinate.longitude; cllocationdistance distdifference = [newlocation distancefromlocation:oldlocation]; int distance = distdifference; if (distance>0.5) { if (isinternetreachable==true) { [self callwebservicesetlocationinbackground:newlocation]; } } [newlocation release]; [oldlocation release]; } need set "required background modes" flag "app registers location updates" utilize core location updated in background. http://i.stack.imgur.com/wtccm.png may help you.
just alter calling web service code method below method. hope work:-
-(void) callwebservicesetlocationinbackground:(cllocation *)location { // remember. running in background if beingness executed. // can't assume normal network access. // bgtask defined instance variable of type uibackgroundtaskidentifier // note expiration handler block ends task. of import // end tasks have started. uiapplication *app = [uiapplication sharedapplication]; uibackgroundtaskidentifier bgtask = [app beginbackgroundtaskwithexpirationhandler:^{ [app endbackgroundtask:bgtask];}]; nslog(@"call web service in background lati = %f , long =%f",location.coordinate.latitude,location.coordinate.longitude); [app endbackgroundtask:bgtask]; bgtask = uibackgroundtaskinvalid; }
thanks.
iphone
No comments:
Post a Comment