我使用Tom的以下代码创建了一个Pdf文件和
我在使用Tom的代码查找我创建的文档时遇到了同样的问题。我搜索我的Mac高清仍然没有文件,该程序不会崩溃。当我查看它显示的日志时,它已存储在以下路径
pdfPathWithFileName String“/ Users / cleota / Library / Developer / CoreSimulator / Devices / B72A97D0-339E-4E79-AED6-4991D3B7C4B7 / data / Containers / Data / Application / 7A7789C4-27C5-45FB-8604-E36865609764 / Documents / Ezy Essay Test.pdf“
但是当我去那里时,这些文件夹(Library / Developer / CoreSimulator / Devices)并不存在它所说的存储位置。请问?
@IBAction func createPdfDocument(sender: AnyObject) {
let fileName: String = "Taumaoe.pdf"
let path:NSArray = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let documentDirectory: AnyObject = path.objectAtIndex(0)
let pdfPathWithFileName = documentDirectory.stringByAppendingPathComponent(fileName as String)
print(pdfPathWithFileName)
generatePdf(pdfPathWithFileName)
}
func generatePdf(filepath: String){
UIGraphicsBeginPDFContextToFile(filepath, CGRectZero, nil)
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 850, 1100), nil)
drawBackground()
}
func drawBackground(){
var context:CGContextRef = UIGraphicsGetCurrentContext()!
// var rect:CGRect = CGRectMake(0, 0, CGSize.height, CGSize.width)
//CGContextSetFillColorWithColor(context, UIColor.greenColor().CGColor)
//CGContextFillRect(context, rect)
var testView = UIView (frame: CGRectMake(0,0,850,1100))
testView.backgroundColor = UIColor.yellowColor()
var label = UILabel (frame: CGRectMake(10,10,100,20))
label.textColor = UIColor.redColor()
label.backgroundColor = UIColor.lightGrayColor()
label.text = "I'am a test label"
testView.addSubview(label)
testView.layer.renderInContext(context)
UIGraphicsEndPDFContext()
//Title of 1st option of MainController
let sexyKeyWordscontroller = UIAlertController(title: "Ezy Essay Saved!", message: "Well done! Your Ezy Essay Pdf document has been saved at the following path: ", preferredStyle: UIAlertControllerStyle.Alert)
let closeButton : UIAlertAction = UIAlertAction(title: "Close",
style: UIAlertActionStyle.Cancel,
handler: {
(alert: UIAlertAction!) in sexyKeyWordscontroller.dismissViewControllerAnimated(true,
completion: nil)
})
sexyKeyWordscontroller.addAction(closeButton)
self.presentViewController(sexyKeyWordscontroller, animated: true, completion: nil)
}
由于
答案 0 :(得分:1)
如果您在按钮事件中打印出GeoFenceObserversationService.getInstant().addGeofences();
,您将获得文件路径。当您有文件路径打开一个查找窗口并在文件菜单中单击:开始> 转到文件夹
您打印出来的路径如下所示:
/用户/用户名/库/开发商/ CoreSimulator /设备/...
将其复制到路径
中的“转到”文件夹中〜/库/开发商/ CoreSimulator /设备/...
当然跳过最后一个" /xp.pdf"在路径中,如果您只想打开文件夹的位置而不是文件本身。