nsurl

How to convert this var string to URL in Swift

a 夏天 提交于 2019-12-03 02:54:25
问题 I need url filepath be a URL (NSURL in old versions of Swift). I have this: let paths = NSSearchPathForDirectoriesInDomains( .documentDirectory, .userDomainMask, true) // NSString *documentsDirectory = [paths objectAtIndex:0]; let documentsDirectory = paths[0] as String var filePath:String? = nil var fileNamePostfix = 0 repeat { filePath = "\(documentsDirectory)/\(dateTimePrefix)-\(fileNamePostfix).mp4" fileNamePostfix += 1 } while (FileManager.default.fileExists(atPath: filePath)) I need to

How to convert NSURL to String in Swift

試著忘記壹切 提交于 2019-12-02 23:26:06
How do you convert an NSURL to a String in Swift? The following: var directoryURL: NSURL var urlString: String = nsurlObject as String Throws the error: Cannot convert value of type 'NSURL' to type 'String' in coercion It turns out there are properties of NSURL you can access (see Swift Reference ): var directoryURL: NSURL var urlString: String = directoryURL.absoluteString // OR var urlString: String = directoryURL.relativeString // OR var urlString: String = directoryURL.relativePath // OR var urlString: String = directoryURL.path // etc. In Swift 3 & 4 , To convert URL to String, you can

What is the correct way to handle stale NSURL bookmarks?

让人想犯罪 __ 提交于 2019-12-02 22:12:49
When resolving an NSURL from a security scoped bookmark, if the user has renamed or moved that file or folder, the bookmark will be stale. Apple's document says this regarding staleness: isStale On return, if YES, the bookmark data is stale. Your app should create a new bookmark using the returned URL and use it in place of any stored copies of the existing bookmark. Unfortunately, this rarely works for me. It may work 5% of the time. Attempting to create a new bookmark using the returned URL results in an error, code 256, and looking in Console reveals a message from sandboxd saying deny file

NSArrayURL , userDefault filePath and URL

杀马特。学长 韩版系。学妹 提交于 2019-12-02 17:17:24
问题 I have one pdf source code and I want to add the Url in Array and use UserDefault let defaults = UserDefaults.standard struct Constants { static let myKeyURL = "myKeyUrl" } I download the Pdf Like This let documentsPath =NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] let fileName = urlString as NSString; let filePath="\(documentsPath)/\(fileName.lastPathComponent)"; After I save the Path like This var arrayUrl = [String]() arrayUrl.append(filePath) self

How to convert this var string to NSURL in swift

混江龙づ霸主 提交于 2019-12-02 16:28:37
I need url filepath be a NSURL. I have this: let paths = NSSearchPathForDirectoriesInDomains( .DocumentDirectory, .UserDomainMask, true) // NSString *documentsDirectory = [paths objectAtIndex:0]; let documentsDirectory = paths[0] as String var filePath:String? = nil var fileNamePostfix = 0 do { filePath = "\(documentsDirectory)/\(dateTimePrefix)-\(fileNamePostfix++).mp4" } while (NSFileManager.defaultManager().fileExistsAtPath(filePath)) I need to convert this to NSURL for use in self.fileOutput.startRecordingToOutputFileURL(<#outputFileURL: NSURL?#>, recordingDelegate: <

iPhone - NSData from local file's URL

做~自己de王妃 提交于 2019-12-02 16:27:36
I have a NSURL object which gives me the path of a local file (in documents folder). I want to populate an NSData object with the contents of this file. Tried using dataWithContentsOfURL: but this fails. I know the file exists because the iPhone SDK returns the path. Can someone please tell me how I can get an NSData object from the URL of a local file? Thanks. // Given some file path URL: NSURL *pathURL // Note: [pathURL isFileURL] must return YES NSString *path = [pathURL path]; NSData *data = [[NSFileManager defaultManager] contentsAtPath:path]; To get this work you just need to do: NSURL

NSURL from String gets truncated, dots on the UIVideoEditorController's video path Swift 2 iOS 8

隐身守侯 提交于 2019-12-02 14:10:12
问题 I can't get the full NSURL of the editedVideoPath, here's my code: // GLOBAL VARIABLES var videoPath = String() var videoURL = NSURL() // Video Editor delegate func videoEditorController(editor: UIVideoEditorController, didSaveEditedVideoToPath editedVideoPath: String) { if saveToPhotoLibrary { if UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(editedVideoPath) { UISaveVideoAtPathToSavedPhotosAlbum(editedVideoPath, self, nil, nil) } print("SAVED TO PHOTO LIBRARY AT: \(editedVideoPath)") }

URL encoding iOS NSURL error

99封情书 提交于 2019-12-02 12:56:07
URL which opens in Firefox,Chrome browsers on desktop, doesn't open in WebView on iPhone. This URL is supposedly accessing a GET request. When creating the NSURL without percentescaping the url doesn't get generated. When using percentescape the url redirects to a Bad url content. Is there a different encoding used on desktop browsers and not on the iPhone? or mobile Safari? Are there different ways to encode the URL in iOS other than using -stringByAddingPercentEscapesUsingEncoding -CFURLCreateStringByAddingPercentEscapes which generates bad request content pages from server. Any help would

A solution to track a batch of HTTP requests in swift 3.0

拈花ヽ惹草 提交于 2019-12-02 12:50:00
I am using swift 3.0 running under iOS 10.0 and I want to craft some code that fires when a batch condition is met. for i in 0 ..< rex { async code, disappears and does it stuff } Imagine the async code is a collection of URL requests, that basically background as soon as I loop thru them. Now how can I fire off more code when "rex" requests have completed? I thought of setting up a timer to watch and check every second, but its surely not a good solution. I thought kicking off another thread to simply watch the data being collected, and fire when its quota is full, but well that's worse then

NSURL is returning nil for a valid URL

邮差的信 提交于 2019-12-02 01:04:18
I have a valid URL for google maps , which if you run in your browser would show an image of a map. However, when I put it inside my Swift code and try to create an NSURL from String it returns nil let urlString = "https://maps.googleapis.com/maps/api/staticmap?maptype=hybrid&center=37.33233141,-122.0312186&path=color:0xff0000|weight:10|37.33233141,-122.0312186|21.422570,%2039.826190&markers=color:blue%7Clabel:S%7C37.33233141,-122.0312186&markers=color:blue%7Clabel:S%7C21.422570,39.826190&zoom=1&size=1080x1920" let url = NSURL(string: urlString) Currently , this returns nil, I don't know why.