我每隔5秒与服务器异步连接.URL是相同的,但每次更改POST主体.现在我每次都从头开始创建NSURL,NSURLRequest和NSURLConnection.
我认为设置连接一次更有效,并进一步使用它.我是新手,不确定是否可能.没有可变的NSURLConnection,但可能需要创建NSURLConnection,如:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
Run Code Online (Sandbox Code Playgroud)
并更改NSMutableURLRequest POST数据以向服务器发送另一个请求.哪条路对不对?
我正在编写一个使用NSURL的Cocoa应用程序 - 我需要删除URL的片段部分(#BLAH部分).
示例:http: //example.com/#blah应最终为http://example.com/
我在WebCore中发现了一些似乎通过使用CFURL功能来实现的代码,但它从未在URL中找到片段部分.我已将其封装在扩展类别中:
-(NSURL *)urlByRemovingComponent:(CFURLComponentType)component {
CFRange fragRg = CFURLGetByteRangeForComponent((CFURLRef)self, component, NULL);
// Check to see if a fragment exists before decomposing the URL.
if (fragRg.location == kCFNotFound)
return self;
UInt8 *urlBytes, buffer[2048];
CFIndex numBytes = CFURLGetBytes((CFURLRef)self, buffer, 2048);
if (numBytes == -1) {
numBytes = CFURLGetBytes((CFURLRef)self, NULL, 0);
urlBytes = (UInt8 *)(malloc(numBytes));
CFURLGetBytes((CFURLRef)self, urlBytes, numBytes);
} else
urlBytes = buffer;
NSURL *result = (NSURL *)CFMakeCollectable(CFURLCreateWithBytes(NULL, urlBytes, fragRg.location - 1, kCFStringEncodingUTF8, NULL));
if …Run Code Online (Sandbox Code Playgroud) 我正在尝试将以下NSString api调用转换为NSURL对象:
http://beta.com/api/token="69439028 "
这是我设置的对象.我用反斜杠转义引号:
NSString *theTry=@"http://beta.com/api/token=\"69439028\"";
NSLog(@"theTry=%@",theTry);
NSMutableURLRequest *url = [[NSURL alloc] URLWithString:theTry];
NSLog(@"url=%@",url);
Run Code Online (Sandbox Code Playgroud)
每次我运行这个,我都会收到这个错误:
2010-07-28 12:46:09.668 RF[10980:207] -[NSURL URLWithString:]: unrecognized selector sent to instance 0x5c53fc0
2010-07-28 12:46:09.737 RF[10980:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL URLWithString:]: unrecognized selector sent to instance 0x5c53fc0'
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我如何正确地将此字符串转换为NSURL?
我想创建两个串行队列A和B.其中队列B是队列A的目标.我想在B上排队一些块,并暂停它直到我准备执行它们,但是我想继续执行块在队列A.
如果我暂停B,它还会暂停它的目标队列(队列A)吗?
我的想法是,我想安排这些特定的块(在队列B上)在稍后(未指定的)日期执行但是我不希望它们同时运行(这涉及核心数据^ _ ^)而我不这样做想要处理信号量.但是我希望队列A继续处理它的块,而B则被暂停
如果不清楚这里是一些示例代码
dispatch_queue_t queueA = dispatch_queue_create("app.queue.A");
dispatch_queue_t queueB = dispatch_queue_create("app.queue.B");
dispatch_set_target_queue( queueB, queueA );
dispatch_suspend( queueB );
/*
* Add a bunch of blocks to queue B or A
* Where the ones added to A should execute immediately
*/
//Wait till blocks on queue A have finished and start up B
dispatch_resume( queueB );
dispatch_release(queueA);
dispatch_release(queueB);
Run Code Online (Sandbox Code Playgroud) 在iOS中保存UIImage为JPEG,我使用UIImageJPEGRepresentation,但它不采取压缩率以外的选项.我希望保存UIImage到progressive JPEG格式,有一个简单的方法吗?
在OS X中看起来有一个NSImageProgressive选项可以保存NSImage为渐进格式.
该方法-isFileReferenceURL是在NSURL类上定义的,但我无法弄清楚这个方法是什么.我认为这决定了URL是否指向实际文件,但事实并非如此.NO即使文件存在,它也会返回.手册说的只是
isFileReferenceURL Returns whether the URL is a file reference URL.
- (BOOL)isFileReferenceURL Return Value YES if the URL is a file reference URL; otherwise, NO.
Availability Available in iOS 5.0 and later. (Symbol is present in iOS 4, but performs no operation.) Declared In NSURL.h
Run Code Online (Sandbox Code Playgroud)
这个方法是什么?什么是文件引用URL?这个方法何时返回YES?
我有一些旧代码使用旧的FSFindFolder例程查找特定文件夹.现在我的任务是使代码现代化.起初使用NSFileManager的URLForDirectory似乎是正确的选择.不幸的是,我发现了很多,你可以找到使用文件夹的FSFindFolder不再受支持URLForDirectory.
您可以使用FSFindFolder找到的文件夹列表很长,而且大多数文件夹对我来说都没用.
以下是我需要转换的FSFindFolder常量的部分列表及其URLForDirectory等价物:
FSFindFolder URLForDirectory
============================== ===============
kDesktopFolderType NSDesktopDirectory
kCachedDataFolderType NSCachesDirectory
kApplicationSupportFolderType NSApplicationSupportDirectory
kTemporaryFolderType located by calling NSTemporaryDirectory()
kCurrentUserFolderType located by calling NSHomeDirectory()
kSystemFolderType Not Available
kPreferencesFolderType Not Available
kTrashFolderType Not Available
kAudioComponentsFolderType Not Available
kVolumeRootFolderType Not Available
kSharedUserDataFolderTypeNo Not Available
Run Code Online (Sandbox Code Playgroud)
我的问题:有没有一种标准方法可以在不使用FSFindFolder的情况下找到标记为"不可用"的每个文件夹的路径?
我做了这样的方法:
-(void) doSomething:(NSString *)str
{
}
Run Code Online (Sandbox Code Playgroud)
我这样称呼它
doSomething(foo);
Run Code Online (Sandbox Code Playgroud)
它不起作用.
我有一个课程,用于存储有关手机资产的信息(图像,视频).
我的班级已ResourceURLString定义为此类
@property NSURL *ResourceURL;
Run Code Online (Sandbox Code Playgroud)
我正在设置属性,同时循环assets通过电话
Item.ResourceURLString = [[asset valueForProperty:ALAssetPropertyURLs] objectForKey:[[asset valueForProperty:ALAssetPropertyRepresentations] objectAtIndex:0]];
Run Code Online (Sandbox Code Playgroud)
当用户点击图像时,我想加载图像.
我的代码就是这个
NSData *imageUrl = [NSData dataWithContentsOfURL:[NSURL URLWithString:[CurrentItem.ResourceURL absoluteString]]];
Img = [UIImage imageWithData:imageUrl];
Run Code Online (Sandbox Code Playgroud)
但是Image总是为nil我已经验证了ResourceURL属性包含URL资产: library://asset/asset.JPG?id=82690321-91C1-4650-8348-F3FD93D14613&ext=JPG
多年来,我在 Xcode 的构建设置列表中看到了这一点,但从未研究过它的作用。今天我尝试这样做,发现谷歌非常缺乏有关该主题的任何信息。任何 Objective-C 老手(我猜是 PPC 时代晚期)能否说明这个设置做了(或做了)什么?
iphone ×4
objective-c ×4
cocoa ×2
ios ×2
nsurl ×2
arguments ×1
cocoa-touch ×1
function ×1
jpeg ×1
macos ×1
macos-carbon ×1
uiimage ×1
xcode4 ×1