IOS 防坑指南

本文介绍如何在Swift中实现文件的读写操作,包括创建文件、写入内容及读取文件的具体实现。此外,还涉及黑苹果环境下虚拟机配置与iOS设备连接问题的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 读写文件

  1.  IOS 8 中  stringWithContentsOfFile 已被移除

  2.  创建文件必须放到 应用下 Documents 下面

 

//
//  FileHelper.swift
//  banche56
//
//  Created by 刘志恒 on 15/1/23.
//  Copyright (c) 2015年 v. All rights reserved.
//

import Foundation

class FileHelper {
    
   class func WriteLog(){
    
    let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
    let logSessionName = "GpsLog.txt"
    var  filePath1 = "\(documentsPath)/\(logSessionName)"
    
    
        var path = NSHomeDirectory().d
        var filePath = path + "/GpsLog.txt";
    var fileManager =    NSFileManager.defaultManager();
    var curpath = fileManager.currentDirectoryPath
        var txt =   "我在测试\n hahah"
        
        var data = txt.dataUsingEncoding(NSUTF8StringEncoding)
        
        if( fileManager.fileExistsAtPath(filePath1) == false)
        {
            fileManager.createFileAtPath(filePath1, contents: data, attributes: nil)
        }
        else
        {
        var handle =    NSFileHandle(forWritingAtPath: filePath1)
                 handle?.seekToEndOfFile()
                handle?.writeData(data!)
            
       
            handle?.closeFile()
    }
    
        
     if( fileManager.fileExistsAtPath(filePath1) == false)
     {
        println("写入失败")
    }
    else
     {
        println("写入成功")

    }
   
    }
    
    class func ReadLog(){
        
        let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
        let logSessionName = "GpsLog.txt"
        var  filePath = "\(documentsPath)/\(logSessionName)"
        var fileManager =    NSFileManager.defaultManager()
        
        
        if( fileManager.fileExistsAtPath(filePath))
        {
       
     var msg =   NSString(contentsOfFile: filePath, encoding: NSUTF8StringEncoding, error: nil)
          
        println("读取文件成功" + msg!)
        }
    }
    
}

  2. 黑苹果使用虚拟机安装时

  需注意dios是否开启了虚拟化功能,并且确认vmware是否安装了mac os补丁 VMware_Unlocker

3.黑苹果升级后,无法连接iPhone

黑苹果升级后,iTunes和Xcode 无法显示手机,但实际在系统参数中已显示中iPhone手机,只是在usb3.0接口中

解决方式:将虚拟机的usb参数调整为2.0(原来为3.0)即可解决问题

转载于:https://www.cnblogs.com/shikyoh/p/4244025.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值