Saturday 15 March 2014

iphone - Updating Interface from Result of NSURL Request -


I have an app that updates the interface based on the results of an NSURL request. I removed set it so request when my app comes in the foreground, and only if the current view controller is called "Profailwukantrolr"

My problem is that whenever I Background When I bring the app back, the interface locks for a few seconds. I am trying to fully understand the main / background thread, but I'm not sure that the app What can I do to stay Any help would be great! Thanks!

Load method in my view:

  - (zero) viewDidoadload {[Super Viewedload]; [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector (appReturnsActive) Name: UIApplicationDidBecomeActiveNotification object: nil]; // additional code}   

My application returns active method then:

  - (zero) appReturnsActive {[myTimer cancellation] ; MyTimer = Zero; // only view the updated display if the playback disappears view controller UIViewController * currentVC = self.navigationController.visibleViewController; NSString * name = NSStringFromClass ([currentVC class]); If ([name isEqualToString: @ "profileviewer"]) {[activity indicator startup]; [ACTIVE DIRECTOR TWO STARTING OUT]; LocationManagerProfile.delegate = self; LocationManagerProfile.desiredAccuracy = kCLLocationAccuracyBest; [Start LocationManagerProfileMy location]; }}   

Finally, in my updated update location mode, I get the distance between the user and the location. If the result is equal to 1, then I update the interface to show different buttons.

  - (minus) locationManager: This is where the interface is frozen (CLLocationManager *) manager didUpdateToLocation: (CLLocation *) newLocation fromLocation: (CLLocation *) oldLocation {CLLocation * Current Location = New location; If (current location! = Zero) {[self displaying onMineTrade: @Selector (buttonupdate :) with object: tap waitingToone: no]; }}   

New Method:

  - (minus) buttonUpdate {NSString * userLongitude = [NSString stringWithFormat: @ "% .8f ", current location.Cordinate. Langat]; NSString * userLatitude = [NSString stringWithFormat: @ "% .8f", current location. Coordinate.latitude]; [LocationManagerProfile stopUpdatingLocation]; NSString * Transfers = [[NSUserDefaults Standard Standard Defaults] StringForki: @ "Saved Latitude"]; NSString * Transfers = [[NSUserDefaults standard standard defaults] StringForki: @ "saved length"]; Nsstring * Distansurl = [Nsstring Stringvitformt: @ "Actiteepi://wwwkvebsaitkcom/pejkphp Ltl =% @ & amp; Lonl =% @ & amp; Lt2 =% @ & amp; Lon2 =% @?" , UserLatitude, User Lingitude, Place Latitude, Place Lengthy]; NSDTA * distanceURL reference = [NSDATA DATAVITY CONTENT OFF URL: [NSL URL URLRstring: Distance]]; NSString * distanceInFeet = [[NSString alloc] initWithData: distanceURLResult encoding: NSUTF8StringEncoding]; If ([distanceInFeet isEqualToString: @ "1"]) {UIBarButtonItem * btnGo = [[UIBarButtonItem alloc] initWithTitle: @ "button 1" style: UIBarButtonItemStyleBordered goal: self action: @selector (actionTwo)]; Self.navigationItem.rightBarButtonItem = btnGo; UIBarButtonItem * btnGoTwo = [[UIBarButtonItem alloc] initWithTitle: @ "button two" style: UIBarButtonItemStyleBordered goal: self action: @selector (actionOne)]; Self.navigationItem.rightBarButtonItem = btnGoTwo; Self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects: btnGo, btnGoTwo, zero]; }}   

Your core locks representative methods (for example " done UpdateToLocation < / Code> ", etc.) In the background, all the secondary threads are happening.

To fix your problem, you should modify your UI on the main thread. One of the easiest foundation APIs you can use is:

To fix your problem, move your button-code to a different method and type " ExhibitoronMineTrade "from the old (being called on a separate thread through the CoreLocation delegation protocol) and you should be good to go.

No comments:

Post a Comment