我正在开发app,我大部分时间都在与web服务进行交互.当我在将url转换为请求时将空间转换为%20的某个地方添加空间时,我遇到了问题.我用Google搜索,但根据我的要求找不到任何健康的解决方案,因为它只会在请求网址时更改.这就是我在做的事情.
url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
NSLog(@"Request is : %@", request);
[[NSURLConnection alloc] initWithRequest:request delegate:self];
Run Code Online (Sandbox Code Playgroud)
在NSLog它上面显示%20给出了空间.如果有人知道建议我更好地解决这个问题的方法.这对我来说很棒.提前致谢.
我正在尝试远程玩 .mp3 file
但它给出了以下错误.
The operation couldn’t be completed. (OSStatus error -43.)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
isPlaying = NO;
/*
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"Dar-e-Nabi-Per" ofType:@"mp3"]];
*/
NSURL *url = [NSURL
URLWithString:@"http://megdadhashem.wapego.ru/files/56727/tubidy_mp3_e2afc5.mp3"];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:url
error:&error];
if (error)
{
NSLog(@"Error in audioPlayer: %@",
[error localizedDescription]);
}
else
{
audioPlayer.delegate = self;
[audioPlayer prepareToPlay];
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以指导我在哪里做错了
我正在构建一个小型REST服务来授权用户进入我的应用程序.
有一次,我用来授权用户的UIWebView将转到https://myautholink.com/login.php.此页面使用授权令牌发送JSON响应.关于这个页面的事情是它通过我的授权表格通过GET接收一些数据.我无法使用PHP会话,因为您通过以下方式访问此页面:
header("location:https://myautholink.com/login.php?user_id=1&machine_id=machine_id&machine_name=machine_name&app_id=app_id");
Run Code Online (Sandbox Code Playgroud)
由于标题函数在标题中发送,我不能session_start();同时执行.
我可以使用委托方法获取UIWebView的请求URL而不会出现问题:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSURLRequest *request = [webView request];
NSLog(@"%@", [[request URL] relativeString]);
if([[[request URL] absoluteString] isEqualToString:SPAtajosLoginLink])
{
//Store auth token and dismiss auth web view.
}
}
Run Code Online (Sandbox Code Playgroud)
事情是没有NSURL方法似乎没有参数返回"干净"链接.我查看了所有NSURL url-string相关方法:
- (NSString *)absoluteString;
- (NSString *)relativeString; // The relative portion of a URL. If baseURL is nil, or if the receiver is itself absolute, this is the same as absoluteString
Run Code Online (Sandbox Code Playgroud)
但是absoluteString总是带有GET参数的完整URL,而relativeString总是为零.
我正在摸不着头脑,我似乎无法找到解决方案.任何帮助将不胜感激.
我试图从URL中插入和映像到UIImageView.我使用以下代码来执行此操作.运行程序时遇到困难
NSURL *url = [NSURL URLWithString:urlstring];
Run Code Online (Sandbox Code Playgroud)
在下面的代码中,它在该特定行上显示"Thread 1:signal SIGABRT".有人可以帮助我,并告诉我使用的格式是否正确或我做错了什么?
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"newoffer";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell==nil)
{
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *temp = [product objectAtIndex:indexPath.row];
UILabel *Label = (UILabel *)[cell viewWithTag:201];
Label.text = [temp objectForKey:@"item_name"];
UIImageView *Image = (UIImageView *)[cell viewWithTag:200];
NSString *urlstring=[temp objectForKey:@"image_url"];
NSURL *url = [NSURL URLWithString:urlstring];
NSData *data = [NSData dataWithContentsOfURL:url];
Image.image = [UIImage imageWithData:data];
return cell;
}
Run Code Online (Sandbox Code Playgroud) 我使用此代码UIImage从一个加载URL:
NSURL *imageURL = [NSURL URLWithString:@"http://testwebsite.com/image.png"];
NSData *imageData = [[NSData alloc] initWithContentsOfURL:imageURL];
imageView.image = [UIImage imageWithData: imageData];
Run Code Online (Sandbox Code Playgroud)
但我坚持URL看起来像这样:
http://www.testwebsite.com/getFile?userID=123
这在浏览器中工作正常,但在imageData上面的变量中返回nil .
如何加载来自这样一个模糊的图像URL (即URL从不显示文件名但是重定向到图像文件的图像)?
先感谢您.
我想在NSURL中传递参数.例如,我有
NSURL *url = [NSURL URLWithString:@"http://demo.digi-corp.com:82/Nilesh/betBuddy/api/getEventsXML.php?sp_ID=2"];
Run Code Online (Sandbox Code Playgroud)
哪里sp_ID可以是1,2,3,4等.我该怎么办?请帮帮我.
我想要做的解释如下.
我有一个MP3文件的网址.(例如声音文件)
当用户启动应用程序时,应该开始下载并为此我实现了以下方法:
-(void)viewDidLoad {
[super viewDidLoad];
NSURL *url=[NSURL URLWithString:@"http://xyz.pqr.com/abc.mp3"];
NSURLRequest *req=[NSURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:120];
NSURLConnection *con=[[NSURLConnection alloc] initWithRequest:req delegate:self startImmediately:YES];
if(con){
myWebData=[[NSMutableData data] retain];
} else {
// [MainHandler performSelector:@selector(targetSelector:) withObject:nil];
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
NSLog(@"%@",@"connection established");
[myWebData setLength: 0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSLog(@"%@",@"connection receiving data");
[myWebData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"%@",@"connection failed");
[connection release];
// [AlertViewHandler showAlertWithErrorMessage:@"Sorry, there is no network connection. Please check your network and try …Run Code Online (Sandbox Code Playgroud) 有人可以确认该-checkResourceIsReachableAndReturnError:方法NSURL是否按预期工作.我已经尝试将它用于已知的URL并且它总是返回NO.我正在使用XCode的iPhone模拟器4.1.谢谢.
self.player = [[AVPlayer playerWithURL:[NSURL URLWithString:@"http://myurl.com/track.mp3"]] retain];
Run Code Online (Sandbox Code Playgroud)
我正在尝试为上述轨道制作UIProgressView.如何从该URL获取文件大小和当前文件大小?请帮忙,谢谢!
你可以这样打电话NSPasteboard:
[pboard declareTypes:types owner:self];
Run Code Online (Sandbox Code Playgroud)
这意味着粘贴板稍后会要求所有者根据需要提供类型的数据.然而,我从文档中找不到的东西(也许我错过了明显的流血事件),是否owner保留.
实际上令我担心的是,如果所有者是弱引用,它可能会被释放,如果粘贴板然后尝试从中请求数据,则会导致崩溃.
注意:我应该澄清一点,我对此更感兴趣的是帮助追踪错误,而不是让我的应用程序依赖它.但我也希望澄清文件.
nsurl ×5
ios ×4
iphone ×4
cocoa ×2
uiimageview ×2
appkit ×1
avfoundation ×1
download ×1
ios7 ×1
nspasteboard ×1
nsurlrequest ×1
objective-c ×1
uitableview ×1
uiwebview ×1
xcode ×1