NSURLComponents的使用
来源:互联网 发布:全国网络电视台直播 编辑:程序博客网 时间:2024/05/16 23:51
我们开发中经常会用到NSURL,有时候我们需要对一个url进行分析整理,当然是可以按照RFC 1808的定义去自己分析,但是苹果已经给我们提供了解析url的方法,就是iOS 7时添加的NSURLComponents。
初始化方法如下:
//
- (instancetype)init;
//
- (nullable instancetype)initWithURL:(NSURL *)url resolvingAgainstBaseURL:(BOOL)resolve;
//
+ (nullable instancetype)componentsWithURL:(NSURL *)url resolvingAgainstBaseURL:(BOOL)resolve;
//
- (nullable instancetype)initWithString:(NSString *)URLString;
//
+ (nullable instancetype)componentsWithString:(NSString *)URLString;
常用的属性如下:
@property (nullable, readonly, copy) NSURL *URL;
@property (nullable, readonly, copy) NSString *string NS_AVAILABLE(10_10, 8_0);
@property (nullable, copy) NSString *scheme; // Attempting to set the scheme with an invalid scheme string will cause an exception.
@property (nullable, copy) NSString *user;
@property (nullable, copy) NSString *password;
@property (nullable, copy) NSString *host;
@property (nullable, copy) NSNumber *port; // Attempting to set a negative port number will cause an exception.
@property (nullable, copy) NSString *path;
@property (nullable, copy) NSString *query;
@property (nullable, copy) NSString *fragment;
@property (nullable, copy) NSString *percentEncodedUser;
@property (nullable, copy) NSString *percentEncodedPassword;
@property (nullable, copy) NSString *percentEncodedHost;
@property (nullable, copy) NSString *percentEncodedPath;
@property (nullable, copy) NSString *percentEncodedQuery;
@property (nullable, copy) NSString *percentEncodedFragment;
@property (nullable, copy) NSArray<NSURLQueryItem *> *queryItems NS_AVAILABLE(10_10, 8_0);
比如http://help.baidu.com:80/question?prod_id=1#!/feedback,scheme就是http, host是help.baidu.com, port就是80, path就是/question, query就是prod_id=1, fragment = !/feedback。
- NSURLComponents的使用
- NSURLComponents 使用简介
- NSURL / NSURLComponents
- NSURL / NSURLComponents
- NSURL / NSURLComponents
- NSURL / NSURLComponents
- 关于NSURL NSURLComponents
- GUID使用的使用
- ${}的使用
- 的使用
- @[],@()的使用
- ->的使用
- +、-、*、/、%的使用
- &&的使用
- %:的使用
- Makefile中使用$$的使用
- Makefile中使用$$的使用
- Red5的使用--使用日志
- 编译原理笔记8 自上而下语法分析-…
- css设置背景图
- 编译原理笔记9 自上而下语法分析-…
- 编译原理笔记10 自上而下分析-预…
- terminal中断kill进程
- NSURLComponents的使用
- 编译原理笔记11 自上而下分析-递…
- 谷歌正式推出在线云储存服务…
- 【排序】洛谷 P1059 明明的随机数
- 关于Xcode一直打印AQDefaultDevice
- 编译原理笔记12 自底向上分析技术…
- HDU 1176 免费馅饼 dp
- python网络编程之TCP
- 编译原理笔记13 自底向上分析技术…