2016-04-29 28 views
0

xcodeとswiftを使用してapple用のランニング(ジョギング)アプリを作成しています。xcodeのバージョンは7.0/7.1です。地図が表示され、あなたが走っている場所と時間、距離、ペースを表示します。これはすべて私がデバッグシミュレータを使用するときに動作しますが、ios 8.4を実行しているipadがアプリを開発したので、地図が表示されますが、位置が表示されないため、距離やペースを計算できませんあなたが実行を保存しようとすると、私は場所のエラーが見つかりませんでした。シミュレータでの作業と比較して、実際のデバイスで異なるコードで何を確認するかは不明です。私はこのサイトで見つけたものをいくつか試してみましたが、うまくいかなかったのです。私は位置をシミュレートし、デバッグシミュレーションをnoneに設定しました。私がそれをやった後、私はデバイス上でアプリケーションを削除し、xcodeを再起動してデバイス上で再構築しました。助けをありがとうxcode swift app、locationはシミュレータでは動作しますが、実際のデバイスでは動作しません

@IBAction func startPressed(sender: AnyObject) { 
    startButton.hidden = true 
    promptLabel.hidden = true 

    timeLabel.hidden = false 
    distanceLabel.hidden = false 
    paceLabel.hidden = false 
    stopButton.hidden = false 

    seconds = 0.0 
    distance = 0.0 
    locations.removeAll(keepCapacity: false) 
    timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: "eachSecond:", userInfo: nil, repeats: true) 
    startLocationUpdates() 

    mapView.hidden = false 
    } 

    > // MARK: - CLLocationManagerDelegate extension NewRunViewController: 
    > CLLocationManagerDelegate { func locationManager(manager: 
    > CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { 
    >  for location in locations as! [CLLocation] { 
    >  let howRecent = location.timestamp.timeIntervalSinceNow 

     if abs(howRecent) < 10 && location.horizontalAccuracy < 20 { 
     //update distance 
     if self.locations.count > 0 { 
      distance += location.distanceFromLocation(self.locations.last) 

      var coords = [CLLocationCoordinate2D]() 
      coords.append(self.locations.last!.coordinate) 
      coords.append(location.coordinate) 

      let region = MKCoordinateRegionMakeWithDistance(location.coordinate, 500, 500) 
      mapView.setRegion(region, animated: true) 

      mapView.addOverlay(MKPolyline(coordinates: &coords, count: coords.count)) 
     } 

     //save location 
     self.locations.append(location) 
     } 
    } 
    } 
} 

答えて

0

あなたのGPSの場所を使用するユーザーの許可を求めましたか? Info.plistにキーを追加しましたか?

<key>NSLocationAlwaysUsageDescription</key> 
    <string>Get Your Location </string> 
    <key>NSLocationWhenInUseUsageDescription</key> 
    <string>Get Your Location For </string> 

コードを投稿できますか?

+0

はい私はそれをして、実際に起動する前に新しいランページに行くとポップアップします – covkiller

関連する問題