欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

ios開發(fā)保存文件,ios文件存儲

iOS開發(fā)生成txt文件

一開始我用的方法一寫,但是后來發(fā)現(xiàn)在高系統(tǒng)上報錯(大概報錯內(nèi)容:NSCocoaErrorDomain:257)。

張家界ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:18980820575(備注:SSL證書合作)期待與您的合作!

后來解決了,做個記錄。

1、在低于iOS13的系統(tǒng)中。用創(chuàng)建文件夾的形式可以如下:

+ (NSString *)tmpLogPath

{

NSString *docPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Library"];

NSString *dirPath = [docPath stringByAppendingPathComponent:@"mylog"];

NSString *filePath = [dirPath stringByAppendingPathComponent:@"tmpLog.txt"];

return filePath;

}

+ (void)writeTmpLog:(NSString *)aMsg

{

NSString *filePath = [[self class] tmpLogPath];

if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {

? ? BOOL isDir = NO;

? ? BOOL hasDir = [[NSFileManager defaultManager] fileExistsAtPath:filePath isDirectory:isDir];

? ? if (!hasDir || !isDir) {

? ? ? ? [[NSFileManager defaultManager] createDirectoryAtPath:filePath withIntermediateDirectories:NO attributes:nil error:nil];

? ? }

}

NSError *error;

NSString *content =[NSString stringWithContentsOfFile:filePath

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? encoding:NSUTF8StringEncoding

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? error:error];

NSString *newContent = [NSString stringWithFormat:@"%@\n%@",content,aMsg];

[newContent writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];

}

+ (void)clearTmpLog

{

NSString *filePath = [[self class] tmpLogPath];

[@"" writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];

}

2、但是在iOS13上,不能這樣寫。系統(tǒng)會默認(rèn)創(chuàng)建以為***.txt的文件夾,在寫入的時候就出問題了。

會報錯:NSCocoaErrorDomain:257 就是

NSFileReadNoPermissionError = 257,/ /讀取錯誤(權(quán)限問題)

所以可以這樣寫:

+ (NSString *)tmpLogPath {

NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];

NSString *filePath = [documentPath stringByAppendingPathComponent:@"mylog/tmpLog.txt"];

returnfilePath;

}

+ (void)writeTmpLog:(NSString*)aMsg {

NSString*fieldPath = [[self class]tmpLogPath];

NSLog(@"當(dāng)前文件大?。?llu",[self fileSizeWithPath:fieldPath]);

NSFileManager *manager = [NSFileManager defaultManager];

if(![managerfileExistsAtPath:fieldPath]){

? ? NSError*error;

? ? [aMsgwriteToFile:fieldPath atomically:YES encoding:NSUTF8StringEncoding error:error];

? ? if(error) {

? ? ? ? NSLog(@"寫入失敗:%@\n",[error localizedDescription]);

? ? }

}else{

? ? NSError*error;

? ? NSError*writeError;

? ? NSString *content =[NSString stringWithContentsOfFile:fieldPath

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? encoding:NSUTF8StringEncoding

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? error:error];

? ? if(error) {

? ? ? ? NSLog(@"讀取失敗:%@\n",[error localizedDescription]);

? ? }

? ? NSString*newContent = [NSString stringWithFormat:@"%@\n%@",content,aMsg];

? ? [newContentwriteToFile:fieldPath atomically:YES encoding:NSUTF8StringEncoding error:writeError];

? ? if(writeError) {

? ? ? ? NSLog(@"寫入失敗:%@\n",[writeErrorlocalizedDescription]);

? ? }

}

}

//獲取文件大小

+ (unsignedlonglong)fileSizeWithPath:(NSString*)path {

signedlonglongfileSize =0;

NSFileManager *fileManager = [NSFileManager defaultManager];

if([fileManagerfileExistsAtPath:path]) {

? ? NSError*error =nil;

? ? NSDictionary*fileDict = [fileManagerattributesOfItemAtPath:patherror:error];

? ? if(!error fileDict) {

? ? ? ? fileSize = [fileDictfileSize];

? ? }

}

returnfileSize;

}

+ (void)clearTmpLog {

NSError*error;

NSFileManager *manager = [NSFileManager defaultManager];

NSString*filePath = [[selfclass]tmpLogPath];

[managerremoveItemAtPath:filePatherror:error];

if(error) {

? ? NSLog(@"刪除失敗:%@\n",[error localizedDescription]);

}

}

ios開發(fā) 怎么把音樂文件存入iphone音樂庫

1、將手機(jī)與電腦用usb連接,電腦上的itunes自動打開 如果你電腦里沒有安裝itunes軟件的話 請點(diǎn)擊“itunes下載”

2、點(diǎn)擊上面工具欄中文件下的“將文件添加到資料庫”,如果你想把文件夾里所有的歌曲都導(dǎo)入,就選擇“將文件夾添加到資料庫”

3、選擇王傳一的練習(xí),點(diǎn)擊打開

4、在資料庫的音樂里,看到這首練習(xí)已經(jīng)導(dǎo)入了

5、點(diǎn)擊設(shè)備

6、勾選音樂選項下的同步音樂,想把整個音樂庫中的歌曲都導(dǎo)入手機(jī)的話就選擇“整個音樂資料庫”,點(diǎn)擊下面的應(yīng)用即可

蘋果手機(jī)如何保存文件

1.打開蘋果手機(jī)里的應(yīng)用,點(diǎn)擊需要保存的文件。

2.進(jìn)入該文件后,點(diǎn)擊更多圖標(biāo)。

3.在菜單欄內(nèi)選擇“用其他應(yīng)用打開”。

4.選擇存儲到“文件”就可以了。

ios 開發(fā)app 數(shù)據(jù)存儲在哪個文件夾下

簡單的數(shù)據(jù),對安全性要求不高的數(shù)據(jù)可以使用 NSUserDefaults (本質(zhì)上是一個plist)來存儲

相對復(fù)雜點(diǎn)的數(shù)據(jù),可以使用coredata (本質(zhì)上是使用sqlite 來存儲)

對安全性要求較高的數(shù)據(jù),可以使用keychain 來存儲。

文章名稱:ios開發(fā)保存文件,ios文件存儲
URL網(wǎng)址:http://chinadenli.net/article6/dsdgsig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、網(wǎng)站改版、企業(yè)網(wǎng)站制作、虛擬主機(jī)、服務(wù)器托管、定制開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)