コンソールに出力するNSURL
と、次のようになります
。
<AVURLAsset: 0x170232800, URL = assets-library://asset/asset.MOV?id=426C5913-86CF-4476-2DB6-6A9AAC626AF4&ext=MOV>
この URL の id 部分に到達する適切な方法は何ですか? 目標は、文字列を持つこと426C5913-86CF-4476-2DB6-6A9AAC626AF4
です。
次のようなものを使用できます。
NSURL *url = [[NSURL alloc] initWithString:@"assets-library://asset/asset.MOV?id=426C5913-86CF-4476-2DB6-6A9AAC626AF4&ext=MOV"];
NSArray *components = [[url query] componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"=&"]];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
for (NSUInteger idx = 1; idx < components.count; idx+=2) {
params[components[idx - 1]] = components[idx];
}
NSLog(@"params[@id] = %@", params[@"id"]);
この目的のために、NSURL のカテゴリを作成することをお勧めします。
次から始めます。
NSURL *urlAddress = [NSURL URLWithString:yourAddressString];
それで:
[urlAddress scheme] gives the Scheme;
[urlAddress host] gives the host
[urlAddress path], [urlAddress relativePath], [urlAddress query], [urlAddress fragment] or [urlAddress parameterString] gives the correspondent parts of your urlAddress