У меня возникли проблемы с симулятором iOS и, в частности, с настройками настраиваемого местоположения для iPhone. Когда я запускаю приложение при первом запуске симулятора, он находит местоположение пользователя без проблем, однако, если я затем изменю свое местоположение и снова запустил приложение, он будет иметь то же место, что и в первый раз, несмотря на то, что он изменил пользовательское местоположение. Если вместо этого я устанавливаю Debug> Location> none в симуляторе и меняю местоположение в Product> Schemes> Edit Schemes в самом xCode, у меня нет проблем. Однако каждый время Я меняю местоположение таким образом, я должен сначала установить местоположение в none в симуляторе. Это проблема с моим кодом или просто причуда симулятора, которую я бы не нашел с настоящим iPhone?iOS Simulator Пользовательские проблемы с местоположением
import UIKit
import CoreLocation
import MapKit
var userLocationCity : String!
var userLocationDate : String!
var safeUsername : String!
class TinderViewController: UIViewController, CLLocationManagerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
PFGeoPoint.geoPointForCurrentLocationInBackground { (geopoint: PFGeoPoint!, error: NSError!) -> Void in
if error == nil {
println(geopoint)
var longitude :CLLocationDegrees = geopoint.longitude
var latitude :CLLocationDegrees = geopoint.latitude
var location = CLLocation(latitude: latitude, longitude: longitude) //changed!!!
println(location)
var formatter: NSDateFormatter = NSDateFormatter()
formatter.dateFormat = "dd-MM-yyyy"
let stringDate: String = formatter.stringFromDate(NSDate())
userLocationDate = stringDate
println(userLocationDate)
CLGeocoder().reverseGeocodeLocation(location, completionHandler: {(placemarks, error) -> Void in
if error != nil {
println("Reverse geocoder failed with error" + error.localizedDescription)
return
}
if placemarks.count > 0 {
println(userLocationCity)
let pm = placemarks[0] as CLPlacemark
println(pm.locality)
println(userLocationCity)
userLocationCity = pm.locality
println(userLocationCity)
user["location"] = userLocationCity
user.save()
let string1 = PFUser.currentUser().objectId
let string2 = "ID_"
safeUsername = string2 + string1
var locate = PFObject(className: safeUsername)
locate.setObject(userLocationCity, forKey: "location")
locate.setObject(userLocationDate, forKey: "date")
locate.saveInBackgroundWithBlock {
(success: Bool!, error: NSError!) -> Void in
if success == true {
println("Score created with ID: \(locate.objectId)")
} else {
println(error)
}
}
}
else {
println("Problem with the data received from geocoder")
}
})
// user["location"] = geopoint
// user.save()
}
}
}