參考資料:RFC 1808 文件、How to Parse an NSURL Object
說明:
ios在URL的使用下,除了可以利用URL Scheme的方式,呼叫外部app,或者開啟iTunes等應用<相關文章:ios URL Scheme Reference、app溝通其他外部程式(一)>,還可以依照RFC 1808的規則,去解析URL的成分。
<scheme>://<net_loc>/<path>;<params>?<query>#<fragment>
根據規則,可以解析URL的成分,如下:
NSURL *url = [NSURL URLWithString: @"http://some-site.com:999/dir1/dir2;param?field-1=value-1&field-2=value-2#anchor1"]; NSLog(@"Scheme: %@", [url scheme]); NSLog(@"Host: %@", [url host]); NSLog(@"Port: %@", [url port]); NSLog(@"Path: %@", [url path]); NSLog(@"Relative path: %@", [url relativePath]); NSLog(@"Path components as array: %@", [url pathComponents]); NSLog(@"Parameter string: %@", [url parameterString]); NSLog(@"Query: %@", [url query]); NSLog(@"Fragment: %@", [url fragment]);
The output is shown below:
As always , if you have any question , feel free to contact me.
有任何問題,請聯絡我
歡迎轉載,請註明出處,感謝。
沒有留言:
張貼留言