0
私は脱獄iPhoneのために開発しています。私はiOS 5の本を読んでいます。現在、私は本のロケーションコードを使用していて、これを少し変更しました。私がコードで行った変更は、テキストファイルに場所を書いていることです。しかし、プログラムがクラッシュします。同じプログラムを修正することなく完全に動作していますが。ここでテキストファイルに場所を書き込もうとします
コードです:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = 2.0f;
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
FILE *file = fopen("/usr/locations.txt", "a");
if (!file)
{
fprintf(file, "Error opening file");
}
if (startingPoint == nil)
self.startingPoint = newLocation;
NSString *latitudeString = [NSString stringWithFormat:@"%g\u00B0",
newLocation.coordinate.latitude];
latitudeLabel.text = latitudeString;
NSNumber *latitude = [[NSNumber alloc] initWithDouble:newLocation.coordinate.latitude];
NSNumber *longitude = [[NSNumber alloc] initWithDouble:newLocation.coordinate.longitude];
NSString *longitudeString = [NSString stringWithFormat:@"%g\u00B0",
newLocation.coordinate.longitude];
longitudeLabel.text = longitudeString;
NSString *horizontalAccuracyString = [NSString stringWithFormat:@"%gm",
newLocation.horizontalAccuracy];
horizontalAccuracyLabel.text = horizontalAccuracyString;
NSString *altitudeString = [NSString stringWithFormat:@"%gm",
newLocation.altitude];
altitudeLabel.text = altitudeString;
NSString *verticalAccuracyString = [NSString stringWithFormat:@"%gm",
newLocation.verticalAccuracy];
verticalAccuracyLabel.text = verticalAccuracyString;
CLLocationDistance distance = [newLocation
distanceFromLocation:startingPoint];
NSString *distanceString = [NSString stringWithFormat:@"%gm", distance];
distanceTraveledLabel.text = distanceString;
struct tm *local;
time_t t;
t = time(NULL);
local = localtime(&t);
fprintf(file, "Local time and Date: %s ", asctime(local));
//----------------- ------------------------------------------------------------
fprintf(file, "Latitude = %lf, Longitude = %lf \n",
newLocation.coordinate.latitude, newLocation.coordinate.longitude);
fclose(file);
}
ファイルシステムへのアクセスについて[Appleのドキュメント](https://developer.apple.com/library/ios/#documentation/FileManagement/Conceptual/FileSystemProgrammingGUide/Introduction/Introduction.html)を読んだことがありますか?それを読んでください。 – JoePasq
今、私はコンソール上で位置を印刷したいだけです。しかし、私はそうすることもできませんでした。私の開発IDEはXcode 4.2で、iOSのバージョンは5.0.1です –