Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing BubbleWrap::HTTP to send device's location when app entered background
    text
    copied!<p>In my app I want to submit the device's location when in background to a web app. Currently I am using <a href="https://github.com/rubymotion/BubbleWrap" rel="nofollow">BubbleWrap</a> for the POST request.</p> <p><strong>Note, that I may be able to use anything other than BubbleWrap if needed.</strong></p> <p>The current behavior is the following:</p> <ol> <li>I start up the app</li> <li>I bring it to background</li> <li>[Waiting for request on web app, watching the logs, nothing happens]</li> <li>I bring the app to the foreground</li> <li>The app sends the device's location</li> </ol> <p>What should happen:</p> <ol> <li>I start up the app</li> <li>I bring it to background</li> <li>The app sends the device's location</li> <li>The app keeps listening for significant location changes and sends its location on significant change</li> </ol> <p>This is the code:</p> <pre><code>class AppDelegate def application(application, didFinishLaunchingWithOptions:launchOptions) [ommitted] UIApplication.sharedApplication.registerForRemoteNotificationTypes(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound) true end def applicationDidEnterBackground(application) @locationManager.startMonitoringSignificantLocationChanges end def applicationDidEnterForeground @locationManager.stopMonitoringSignificantLocationChanges end def application(app, didRegisterForRemoteNotificationsWithDeviceToken:deviceToken) @device_token = deviceToken.description.gsub(" ", "").gsub("&lt;", "").gsub("&gt;", "") # Log the push notification to the console puts @device_token end def application(app, didFailToRegisterForRemoteNotificationsWithError:error) show_alert "Error when registering for device token", "Error, #{error}" end def device_token @device_token end def location_manager if @locationManager.nil? @locationManager = CLLocationManager.alloc.init @locationManager.setDesiredAccuracy(KCLLocationAccuracyBest) @locationManager.delegate = self end @locationManager end # iOS &gt;= 4 def locationManager(manager, didUpdateToLocation:current_location, fromLocation:last_location) puts "Location #{current_location} [iOS 5]" end # iOS &gt;= 6 def locationManager(manager, didUpdateLocations:locations) data = {latitude: locations.last.coordinate.latitude, longitude: locations.last.coordinate.longitude, device_token: @device_token } BW::HTTP.post("http://192.168.1.100:4567/", {payload: data}) do |response| if response.ok? #json = BW::JSON.parse(response.body.to_str) #p json['id'] else App.alert(response.error_message) end end end def locationManager(manager, didFailWithError:error) puts "failed" end def show_alert(title, message) alert = UIAlertView.new alert.title = title alert.message = message alert.show end end </code></pre> <p>Additional info:</p> <ul> <li>I have declared the following in my Rakefile <code>app.info_plist['UIBackgroundModes'] = ['location']</code>.</li> </ul> <p>Any hints or tips on why this is may not be working?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload