我正在创建和无线电应用程序,其中我必须检查身份验证,并在成功登录后,我得到了.pls文件,其中有实际的网址,必须播放,所以任何人都知道如何解析.pls文件,并获得.pls文件内的网址。
发布于 2015-09-23 21:38:50
在我的示例中,主包中有一个WWEMAC.pls文件。其中存在多个url,我只能提取这些url,并以字符串格式将它们添加到数组中。下面的代码对我很有效。
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"WWEMAC" ofType:@"pls"];
NSError *errorReading;
NSArray *linesOfText = [[NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&errorReading] componentsSeparatedByString:@"\n"];
NSLog(@"Reading error %@",errorReading);
NSString *completeDataInStr = [linesOfText componentsJoinedByString:@" "];
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypeLink error:nil];
NSArray *matches = [detector matchesInString:completeDataInStr options:0 range:NSMakeRange(0, [completeDataInStr length])];
for (NSTextCheckingResult *match in matches)
{
NSString *str = [NSString stringWithFormat:@"%@",match.URL];
NSLog(@"URL str = %@",str);
}
return matches;https://stackoverflow.com/questions/1899139
复制相似问题