nsurl

How can I get the file creation date using URL resourceValues method in Swift 3?

落花浮王杯 提交于 2019-12-06 04:23:10
Thanks to a variety of helpful posts in this forum, I have some code that works for obtaining the Creation Date of a single user-selected NSURL. However, I cannot get the code to work for either a hard-coded NSURL, nor within a loop through an NSFileManager enumerator. I am not a professional programmer; I make apps that are tools for office. My ultimate goal is to simply sort an Array of NSURL objects based on Creation Date. The code I am using is below, which functions just fine as is, but if I try to use the commented line to evaluate a specific PDF file, I get the following error: I get

Check string containing URL for “http://”

点点圈 提交于 2019-12-06 03:39:49
问题 I am trying to check the URL entered by the user, but I am fighting against some errors and warnings. -(BOOL) textFieldShouldReturn:(UITextField *)textField { //check "http://" NSString *check = textField.text; NSString *searchString = @"http://"; NSRange resultRange = [check rangeWithString:searchString]; BOOL result = resultRange.location != NSNotFound; if (result) { NSURL *urlAddress = [NSURL URLWithString: textField.text]; } else { NSString *good = [NSString stringWithFormat:@"http://%@",

Downloading a large file in iOS app

三世轮回 提交于 2019-12-06 01:51:26
I'm trying to clean up some existing code that downloads a large file from a server in chunks, checks the checksum on each 50 packets, then stitches them together. I'm having some trouble to see if it's the most efficient way as right now it crashes some time because of memory issues. If I don't have the checksum, it does not seem to crash, but I would prefer if I could check my files first. @property (nonatomic, retain) NSMutableData * ReceivedData; - (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSData *sequencePacketData = [[NSData alloc] initWithData:self.ReceivedData];

Cyrillic symbols in URL

拜拜、爱过 提交于 2019-12-06 01:10:20
App crashes with following url: let jsonUrl = "http://api.com/алматы/events" let session = NSURLSession.sharedSession() let shotsUrl = NSURL(string: jsonUrl) let task = session.dataTaskWithURL(shotsUrl!) Log: fatal error: unexpectedly found nil while unwrapping an Optional value It's because of cyrillic symbols in url. How can I solve this issue. Thanks for your help! Try this: let encodedUrl = jsonUrl.stringByAddingPercentEncodingWithAllowedCharacters(URLQueryAllowedCharacterSet) Swift 4 Using String Extension Create a swift file named String+Extension.swift and paste this code import UIKit

How do I convert url.query to a dictionary in Swift?

江枫思渺然 提交于 2019-12-06 00:43:51
问题 I have a URL coming in to the AppDelegate method: func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool { } The URL looks like www.wesite.com/shareplace.html?placeid=123 . How can it be converted to a dictionary for easy access? I found some code on some website, but it's showing an error in Xcode 9: extension URL { var queryDictionary: [String: AnyObject]? { return URLComponents(url: self, resolvingAgainstBaseURL: false)?

Proper way to access image in saved photos using NSURL and upload to S3?

纵饮孤独 提交于 2019-12-05 22:06:11
I'm using this code to upload an image to S3 AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager]; AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new]; uploadRequest.bucket = @"my-photo-bucket"; uploadRequest.key = @"test_upload"; long long fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:self.imageUrl.path error:nil][NSFileSize] longLongValue]; uploadRequest.contentLength = [NSNumber numberWithUnsignedLongLong:fileSize]; uploadRequest.body = self.imageUrl.absoluteURL; [[transferManager upload

Read a text file with NSURL in Swift

自作多情 提交于 2019-12-05 20:33:46
问题 I want to read and display the content of a text file that is located at an URL. I am coding a Mac App for Yosemite and I need to use Swift but I stuck on this. Here is my code: let messageURL = NSURL(string: "http://localhost:8888/text.txt") let sharedSession = NSURLSession.sharedSession() let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(messageURL!, completionHandler: { (location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in var urlContents =

Create a directory and store files inside it in Swift

落爺英雄遲暮 提交于 2019-12-05 20:14:30
i am creating a directory so that i can save temp videos onto it as TempVideos is a folder now my video clips will be inside the folder... func createTempDirectoryToStoreVideos(){ var error: NSError? let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true) let documentsDirectory: AnyObject = paths[0] tempVideoPath = documentsDirectory.stringByAppendingPathComponent("TempVideos") if (!NSFileManager.defaultManager().fileExistsAtPath(tempVideoPath!)) { NSFileManager.defaultManager() .createDirectoryAtPath(tempVideoPath!,

How to exclude file from backup with Swift 2?

你说的曾经没有我的故事 提交于 2019-12-05 18:20:48
I had this working great with Swift 1.2 as I used the filePath as a string. Now Swift 2 wants us all to use URL paths I can't get this to work even though i'm reading through their docs. I have; var fileName = "myRespondusCSV.csv" let fileManager = NSFileManager.defaultManager() let documentsURL = fileManager.URLsForDirectory(NSSearchPathDirectory.DocumentDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask) if let documentPath: NSURL = documentsURL.first as NSURL! { filePath = documentPath.URLByAppendingPathComponent(fileName) print(filePath) } else { fileManager.createFileAtPath

NSURLThumbnailDictionaryKey empty for local file

怎甘沉沦 提交于 2019-12-05 17:39:54
I want to get a thumbnail representation of a file I have to display in my app. I'm using NSURL here: NSDictionary *thumbnails = nil; BOOL success = [fileURL getResourceValue:&thumbnails forKey:NSURLThumbnailDictionaryKey error: &error]; This works fine if I am connected to iCloud, and the URL is a link to a file stored in iCloud. The fileURL is something like: file:///Users/me/Library/Mobile%20Documents/BJXXGLR9R3~com~myapp~icloud/FileStorage/contact-page%20copy.png If I use the same code with a NSURL pointing to a local file, however, the thumbnails dictionary is empty. Here is an example of