nsurl

Cyrillic symbols in URL

廉价感情. 提交于 2019-12-07 18:12:35
问题 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! 回答1: Try this: let encodedUrl = jsonUrl.stringByAddingPercentEncodingWithAllowedCharacters(URLQueryAllowedCharacterSet) 回答2:

How to exclude file from backup with Swift 2?

∥☆過路亽.° 提交于 2019-12-07 10:10:36
问题 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 =

Determine if a Volume is a Disk Image (DMG) from code

我的未来我决定 提交于 2019-12-07 07:05:36
问题 From Objective C (or Swift), I need to determine if a mounted volume is a Disk Image (mounted from a .dmg file). Similar questions led me to NSURL Volume Property Keys, but none of them seem to give the type/protocol of the volume. However, I can see this information with the terminal diskutil function under Protocol : ~/Temp$ diskutil info /dev/disk8 Device Identifier: disk8 Device Node: /dev/disk8 Part of Whole: disk8 Device / Media Name: Apple UDIF read-only Media Volume Name: Not

containerURLForSecurityApplicationGroupIdentifier getting nil value

妖精的绣舞 提交于 2019-12-07 04:51:19
问题 I am making two iPad app that communicate with one file and fetches all the data from one file. I search and find this "containerURLForSecurityApplicationGroupIdentifier" we can create group and store in that. I have write the code below. In entitlement file i write <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.security.app-sandbox</key> <true/> <key>com

Storing an NSURL as a string in Core Data

南笙酒味 提交于 2019-12-07 04:41:06
问题 I'm beginning to play around with Core Data and just have a question around storing something like a URL. I've currently got it configured as a transformable which is working fine however I feel that it's probably storing excess data unnecessarily and since it can be easily represented with text I'm wondering whether I should just be storing the absolute URL as a string and instantiating an NSURL object when it's loaded (I suspect this is the case) and if so how should this be implemented? My

AppleWatch Messages URL works hard coded but not with variables

无人久伴 提交于 2019-12-07 02:59:24
问题 TLDR When I hard code phone numbers into a URL it opens in watch messages correctly, but when I use a variable string with the numbers typed in exactly the same way inside of it, it doesn't. Example: NSURL(string: "sms:/open?addresses=8888888888,9999999999,3333333333&body=Test") Above code works but below code doesn't: let hardCode = "8888888888,9999999999,3333333333" NSURL(string: "sms:/open?addresses=\(hardCode)&body=Test") FULL DETAILS: I am making a URL from variables to open messages on

使用Swift读取Cookie内容

微笑、不失礼 提交于 2019-12-07 00:10:52
前言 一个http请求中,我们经常会涉及到Get请求的URL Param,POST请求的HTTP Body,Response Json,这些都是一个标准REST API标配的元素。 在一些安全验证的API中,通常会涉及到Cookie。当用户成功登陆后,服务器会在Response Header中写入一个Set-Cookie字段,用来标识用户已经登陆(授权)成功,客户端浏览器接收后会把这个Cookie字段保存在客户端本地。当客户端再次请求API时,就会在Request Header中带上这个Cookie值,告诉服务器:嗨,我已经授权过咯,我的cookie值是xxx,我现在要读取一些信息,请放行~ IOS中的网络请求 一个完整的网络请求,需要先确定Request URL,带上参数,然后发送Request,然后接收Response,处理Response Data。 在IOS中,分别对应如下: //Request URL NSURL //一个完整的Request对象 NSURLRequest //发送请求连接的主要操作者 NSURLConnection //包含返回数据的Response NSURLResponse 下面是一个简单的GET请求代码: let request = NSURLRequest(URL: NSURL(string: "http://devonios.com")!)

How to load NSURL which contains hash fragment “#” with UIWebView?

限于喜欢 提交于 2019-12-06 22:14:13
问题 Given a local URL address like index.html Now I need to use UIWebView to load it in iPad. I followed these steps: Create NSURL NSURL *url = [NSURL fileURLWithPath:@"http://mysite.com#page1"]; Load with UIWebView for local HTML/JS/CSS etc [webView loadRequest:[NSURLRequest requestWithURL:url]]; But it doesn't work, because "#" is converted to "%23", so the URL string is http://mysite.com%23page1 My question is, how to fix this auto-conversion issue and let UIWebView access the URL which

Deep link in to iOS Settings' Notifications page?

人走茶凉 提交于 2019-12-06 20:48:04
问题 I know that I can deep link into the Settings page on iOS via UIApplicationOpenSettingsURLString . However, this takes me to a page such as this: Now if I want the user to enable notifications, they have to find Notifications in the list and then enable it. Is there a way to instead directly link them to the Notifications page? (i.e. Going to the same exact page as though they had tapped notifications in the screenshot above.) If not, is there a way to take them to the global notifications

How to chop off file:// from NSURL

最后都变了- 提交于 2019-12-06 18:40:48
问题 I have an NSURL. It is file://localhost/Users/Me/File.xml I want an NSString that is /Users/Me/File.xml Is there some nice function I can use to do this? 回答1: NSURL path method sounds like it does what you want. 来源: https://stackoverflow.com/questions/3057086/how-to-chop-off-file-from-nsurl