gpt4 book ai didi

iphone - 在 iOS 中写入 .kml 文件

转载 作者:行者123 更新时间:2023-11-29 13:38:04 25 4
gpt4 key购买 nike

我想知道如何在应用程序中写入文件。我在这里要做的是,我正在生成一个 KML(使用来自 https://github.com/skjolber/xswi 的类 XMLWriter)。我可以记录 KML,一切正常,现在我要做的是,将此 KML 保存到一个 .kml 文件,然后通过电子邮件将其发送到某个地址。

电子邮件没问题,我想知道如何将此 KML 写入 .kml 文件,然后检索它以通过电子邮件发送。有人可以帮我一个代码片段。

最佳答案

tutorial做到了,然后帮助..生成.kml文件的代码:

NSFileManager *filemgr;
NSData *databuffer;
NSString *dataFile;
NSString *docsDir;
NSArray *dirPaths;

filemgr = [NSFileManager defaultManager];
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
dataFile = [docsDir stringByAppendingPathComponent: @"datafile.kml"];
databuffer = [[xmlWriter toString] dataUsingEncoding: NSASCIIStringEncoding];
[filemgr createFileAtPath: dataFile contents: databuffer attributes:nil];

然后为了检索它,我使用了:

NSFileManager *filemgr;
NSString *dataFile;
NSData *databuffer;
NSString *docsDir;
NSArray *dirPaths;

filemgr = [NSFileManager defaultManager];

// Identify the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];

// Build the path to the data file
dataFile = [docsDir stringByAppendingPathComponent: @"datafile.kml"];
databuffer = [filemgr contentsAtPath: dataFile];

关于iphone - 在 iOS 中写入 .kml 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9976994/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com