我在网络数据库中有2000个位置,用户应该可以在地图上选择这些位置.我可以要求网络数据库只给我一些来自当前位置的位置.
为了使一切顺利和优雅,我首先实例化MKMapView,启动CLLocationManager并等到我得到didUpdateLocations.然后我会尝试从具有完成处理程序的数据库中获取数据.
我是不是该
a)立即获取所有数据
b)以小块或块的形式获取数据?
它最好的方式是什么?
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
self.gotoCurrentLocation()
if let userLocation = manager.location {
GroundHelper.getAllGroundLocations(userLocation) { self.handleWaypoints($0!) }
}
}
private func handleWaypoints(grounds: [Ground]) {
mapView.addAnnotations(grounds)
}
// MARK: - Helper Methods
typealias GPXCompletionHandler = ([Ground]?) -> Void
class func getAllGroundLocations(userlocation: CLLocation, completionHandler: GPXCompletionHandler) {
let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
dispatch_async(dispatch_get_global_queue(priority, 0), { ()->() in
var results = RestApiManager.sharedInstance.getGPS(userlocation, limit: 50)
// return first 50 results
dispatch_async(dispatch_get_main_queue(), {
var grounds = [Ground]()
for result in …Run Code Online (Sandbox Code Playgroud) 我得到ERROR ITMS-90497,Invalid Image Asset -Top Shelf Image - must be opaque使用这一形象时:
我只是测试这个图像以使其工作并尝试向TestFlight提交tvOS应用程序.
好吧,只是为了开始,继承我的代码:
import UIKit
import ForecastIO
class Weather {
var temp: Float
var condition: String
var wind: Float
var precip: Float
init() {
DarkSkyClient(apiKey: "<api key>").getForecast(latitude: Utils().getLat(), longitude: Utils().getLong()) { result in
switch result {
case .success(let currentForecast, _):
self.temp = (currentForecast.currently?.temperature)!
self.condition = (currentForecast.currently?.summary)!
self.wind = (currentForecast.currently?.windSpeed)!
self.precip = (currentForecast.currently?.precipitationProbability)!
case .failure(let error):
print(error)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以我的错误出现了,因为我正在尝试初始化API调用内部的temp.我知道这不是最可靠的方法,但我试图让它开始工作.
第一个错误是:
在所有成员初始化之前,由关闭捕获的"自我"
在线上 DarkSkyClient(apiKey: "").getForecast(latitude: Utils().getLat(), longitude: Utils().getLong()) { result in
我的第二个错误:
从初始化程序返回而不初始化所有存储的属性
在倒数第二个 }
现在,显然我没有正确初始化.我无法找到正确的方法来完成我的最终目标.也许我这样做完全错了?
我目前正在尝试获取当前用户的设备移动速度。这是我的代码:
import UIKit
import Foundation
import CoreLocation
class ViewController: UIViewController, CLLocationManagerDelegate {
let manager = CLLocationManager()
var currentSpeed = 0.0
override func viewDidLoad() {
super.viewDidLoad()
manager.requestWhenInUseAuthorization()
manager.delegate = self
manager.desiredAccuracy = kCLLocationAccuracyHundredMeters
manager.startUpdatingLocation()
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print(manager.location?.speed)
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print("Error: \(error.localizedDescription)")
}
Run Code Online (Sandbox Code Playgroud)
唯一的问题是它会打印 "Optional(-1,0)"
我在这里先向您的帮助表示感谢。
我正在使用Xcode 7,Swift 2和iOS9.我想使用NSURLSession连接到Web服务,但是当我尝试连接时出现以下错误:
2015-10-13 16:07:33.595 XCTRunner[89220:4520715] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9813)
2015-10-13 16:07:33.604 XCTRunner[89220:4520571] Error with connection, details: Error Domain=NSURLErrorDomain Code=-1202 "The certificate for this server is invalid. You might be connecting to a server that is pretending to be “domainapi.com” which could put your confidential information at risk." UserInfo={NSURLErrorFailingURLPeerTrustErrorKey=<SecTrustRef: 0x7fac7b6facc0>, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?,
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
func request( dataPost : String, successHandler: (response: String) -> Void)-> String {
let destination:String = "https://domainapi.com:8743/WebService/sendData"
let request …Run Code Online (Sandbox Code Playgroud) 我正在寻找 1-60 之间任意数字的正则表达式,这是我目前所拥有的:
[0-6][0-9]
超级简单。当我输入像 950 这样的数字时,它会捕获 50,忽略前面的 9。
提前致谢。