我有一个NSString存储保存文件的路径:
NSString *filePath = [NSString stringWithFormat:
@"%@/someFolder/%@",
NSHomeDirectory(),
[NSString stringWithFormat:@"%@",[self.fileName stringByAppendingPathExtension:@"txt"]]];
Run Code Online (Sandbox Code Playgroud)
它没关系 - 当我记录它时,我得到:
/Users/username/someFolder/fileName.txt
Run Code Online (Sandbox Code Playgroud)
所以我的下一步是从中创建一个NSURL对象NSString.我这样做了:
NSURL *pathURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@", filePath]];
NSLog(@"URL = %@", pathURL);
Run Code Online (Sandbox Code Playgroud)
但回应是:
URL = (null)
Run Code Online (Sandbox Code Playgroud)
这有什么不对?我该怎么做才能正确?
我想用一些其他组件替换myurl中的一些组件,但它不起作用..
这是我的代码段:
NSString *Url =@"http://www.myData.com/pageId=aaa&pageSize=bbb&page=2"
Run Code Online (Sandbox Code Playgroud)
在上述网址我想取代aaa与str1和bbb与str2..
[Url stringByReplacingOccurrencesOfString:@"aaa" withString:str1];
[Url stringByReplacingOccurrencesOfString:@"bbb" withString:str2];
NSLog(@"Final Url = %@",Url);
Run Code Online (Sandbox Code Playgroud)
最后当我看到我的日志,Final Url不替换aaa用str1,并bbb用str2..
谢谢阅读...
我正在为Stack Exchange API创建一个iOS客户端.经过漫长的战斗,我终于设法实现了身份验证 - 这给了我一个令牌,我坚持使用URL.令牌有效时,URL如下所示:
https://api.stackexchange.com/2.1/me/associated?key=_____MY_SECRET_KEY______&access_token=_____ACCESS_TOKEN_:)_____
Run Code Online (Sandbox Code Playgroud)
当有效时,它会将我带到网页中的这个JSON:
{"items":[{"site_name":"Stack Overflow","site_url":"http://stackoverflow.com","user_id":1849664,"reputation":4220,"account_id":1703573,"creation_date":1353769269,"badge_counts":{"gold":8,"silver":12,"bronze":36},"last_access_date":1375455434,"answer_count":242,"question_count":26},{"site_name":"Server Fault","site_url":"http://serverfault.com","user_id":162327,"reputation":117,"account_id":1703573,"creation_date":1362072291,"badge_counts":{"gold":0,"silver":0,"bronze":9},"last_access_date":1374722580,"answer_count":0,"question_count":4},...
Run Code Online (Sandbox Code Playgroud)
我用这段代码得到了正确的JSON:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.stackexchange.com/2.1/me/associated?key=__SECRET_KEY_:)__&access_token=%@", [[NSUserDefaults standardUserDefaults] objectForKey:@"token"]]];
NSData *jsonData = [NSData dataWithContentsOfURL:url];
if (jsonData)
{
NSDictionary *JSON = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:nil];
}
Run Code Online (Sandbox Code Playgroud)
但是,当我手动使令牌无效时,URL看起来仍然相同,浏览器中的页面显示如下:
{"error_id":403,"error_name":"access_denied","error_message":"`key` is not valid for passed `access_token`, token not found."}
Run Code Online (Sandbox Code Playgroud)
但是,dataWithContentsOfURL:总是零.为什么?我究竟做错了什么?
我得到一个NSError返回:
Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x1dd1e9f0 {NSURL=https://api.stackexchange.com/2.1/me/associated?key=key((&access_token=to??ken))}
Run Code Online (Sandbox Code Playgroud) 这似乎是一个常见的问题,但我无法从迄今为止看到的答案中找出任何结论.我有一个iPhone应用程序,它使用子类NSMutableArray来存储对象,以及一些其他属性.子类是skhCustomArray.子类初始化很好,没有对象skhCustomArray,我将它分配给我的视图控制器的属性,这是一个指向skhCustomArray.
prescriptionListVC* newPrescList = [[prescriptionListVC alloc] initWithNibName:@"PrescriptionList" bundle:nil];
newPrescList.curPersonPrescriptions = [personDetails objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
这很好.然而,当我将我的视图控制器管理的视图推送到导航控制器堆栈时,方法中的count numberOfRowsInSection方法会崩溃应用程序,请参见下文.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [curPersonPrescriptions count];
Run Code Online (Sandbox Code Playgroud)
}
可能是什么导致了这个?没有对象的有效自定义数组如何才能返回有效计数?我哪里错了?谢谢.
我有这个代码:
NSLog([url path]);
if([url path] == @"/connect/login_success.html") {
NSLog("IT WORKZ");
}
Run Code Online (Sandbox Code Playgroud)
当我运行我的应用程序时,请登录等...我的控制台说:
2010-05-04 23:49:57.297 Framebook Test Application[8069:a0f] /connect/login_success.html
Run Code Online (Sandbox Code Playgroud)
但它也应该打印IT WORKZ到控制台,它不会.
谁能帮我?谢谢.
好吧,我想从下拉菜单(菜单项列表)中的一个项目作为链接,在safari中打开一个网址/网站 - 就是这样.当这么简单时,为什么没有人在这里提出一个线索 - 我在Xcode中尝试了许多不同的方式,使用Apple Xcode Samples ...我想我需要一个AppDelegate.m,拖动或链接一些部分,获取动作..我没能把它带到某个地方 - 现在我迷路了.任何建议/帮助/链接/提示将非常感谢解决这个"简单"问题...
使用Xcode/Interface Builder 3.2.6 - 请帮助或我完全疯了,疯了,我现在将崩溃我的f ...现在 - 谢谢
有没有一种直接的方法将冒号分隔的路径(即"Macintosh HD:用户:stuarttevendale:Documents:DBTest.db")转换为NSURL(即"file:// localhost/Users/stuarttevendale/Documents/DBTest .D b")?
我想向不同的服务器发出请求我只想填写文本字段中的url或ip地址.我建立了不同的解决方案,但它们都是假的.我觉得这个我很接近.
这是我到目前为止构建的内容:
NSString *part0 = @"http://";
NSString *part1 = [NSString stringWithFormat:@"%@" , _serveradres.text ];
NSString *part2 = @"/API/";
NSString *compURL = [NSString stringWithFormat:@"%@" , part0 , part1 , part2 ];
NSURL *url = [NSURL URLWithString:compURL];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
Run Code Online (Sandbox Code Playgroud)
只有地址不同,api的所有方式都在同一个地方.
后来我想制作一个可以选择http或https的开关