我想NSURLConnection
在后台模式下做,因为它的响应有很多数据.论坛要求使用Apple的有限长度编码didEnterBackground
.但我想避免使用我通过下面的代码它.相反NSOperation
有NSInvocation
作为,但它不工作.connectToServer
有NSURLConnection
操作.请帮忙吗?didReceiveData
,didReceiveResponse
委托方法不调用?
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
selector:@selector(connectToServer)
object:nil];
[queue addOperation:operation];
[operation release];
[queue autorelease];
-(void)connectToServer
{
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSURLConnection *theConnection = [[[NSURLConnection alloc] initWithRequest:theRequest delegate:self] autorelease];
if( theConnection )
{
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"theConnection is NULL");
}
}
Run Code Online (Sandbox Code Playgroud) 我收到addressString后调用此函数:
[[self geocoder] geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *error) {
if (error) {
block(nil, nil, error);
} else {
CLPlacemark *placemark = [placemarks onlyObject];
block(placemark, self.name, error);
}
}];
Run Code Online (Sandbox Code Playgroud)
它返回地标为nil,错误为:Error Domain = kCLErrorDomain Code = 8"操作无法完成.(kCLErrorDomain error 8.)"
我的地址字符串是从这个字典中为placeDictionary [@"formatted_address"]检索的:
placeDictionary =
{
"address_components" = (
{
"long_name" = "Palolem Beach";
"short_name" = "Palolem Beach";
types = (
"natural_feature",
establishment
);
},
{
"long_name" = "South Goa";
"short_name" = "South Goa";
types = (
"administrative_area_level_2",
political
);
},
{
"long_name" = …
Run Code Online (Sandbox Code Playgroud) 在Xcode 4的Build Settings中,有两个位置可以为每种构建类型输入配置文件.第一个是"Ad Hoc","Debug"和"Release".其中每个都有另一个位置,可以放入名为"Any iOS SDK"的配置文件中.我需要填写两者吗?这些有什么区别?
我正在尝试对字符串进行URL编码以形成来自objective-c的GET请求.
NSString *params = @"'Decoded data!'/foo.bar:baz";
NSRunAlertPanel( @"Error", [params urlEncoded], @"OK", nil, nil );
Run Code Online (Sandbox Code Playgroud)
这是扩展NSString的类别
-(NSString *) urlEncoded
{
NSString *encoded = (NSString *)CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef)self,
NULL,
(CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
kCFStringEncodingUTF8 );
return encoded;
}
Run Code Online (Sandbox Code Playgroud)
所以第一次运行它我就回来了
1606410046ecoded 1606410784ata2270.000000foo.bar0X1.001716P-1042baz
Run Code Online (Sandbox Code Playgroud)
从对话框中.
我再次运行后立即得到了这个
1606410046ecoded 1606410944ata227369374562920703448982951250259562309742470533728899744288431318481119278377104028261651081181287077973859930826299575521579020410425419424562236383226511593137467590082636817579938932512039895040.000000foo.bar0X1.66E6156303225P+771baz
Run Code Online (Sandbox Code Playgroud)
然后,如果我再次运行它,它会回到第一个.这真的很奇怪.
如果params设置为@"&"或@"",我只需在对话框中找回"2"(不带引号).
还有一种方法可以在警告对话框中显示%符号吗?
谢谢
我的应用程序将全屏显示,但我无法找到解释如何更改状态栏属性的文档.
如何更改状态栏属性?
我想使用设置应用程序中显示的细条纹背景和桌面视图后面的许多其他iPhone应用程序.是否已经包含在某些图形库中?如何让它显示在UIView或UITableView中?
细条纹http://img.skitch.com/20090630-p783xugab8i9c7x2c63t3ped52.jpg
我正在使用一组Constant.m
文件,每个目标一个,为每个目标定义特定的东西.例如:
// Constants.h
extern NSString * const kDatabaseFileName;
//Constants.m
NSString * const kDatabaseFileName = @"target_one.sqlite";
Run Code Online (Sandbox Code Playgroud)
我还想为每个目标定义一个NSArray:
NSArray * const kLabelNames = [[NSArray alloc] initWithObjects:
@"nameLabel", @"addressLabel", nil];
Run Code Online (Sandbox Code Playgroud)
但是这给出了"错误:初始化元素不是常数".使用'arrayWithObjects`也不起作用.这是因为我的数组中的字符串不是常量吗?
如何将数组设置为全局常量?谢谢.
我想知道是否有相当于MySQL SELECT * FROM table ORDER BY sth
来获取所有结果.
我正在开发一个应用程序,我使用了Pan Gesture以及Swipe Gesture.因此,每次我执行Swipe Gesture时,Pan手势中的方法总是被调用,并且Swipe Gesture方法不会被调用.
所有的手势方法之间有没有优先权?
iphone uigesturerecognizer ios uiswipegesturerecognizer uipangesturerecognizer
我的mapview工作正常,但放在地图上的图钉标题为美国.我该如何更改此标题?
MKCoordinateRegion thisRegion = {{0.0,0.0}, {0.0,0.0}};
thisRegion.center.latitude = 22.569722;
thisRegion.center.longitude = 88.369722;
CLLocationCoordinate2D coordinate;
coordinate.latitude = 22.569722;
coordinate.longitude = 88.369722;
thisRegion.center = coordinate;
MKPlacemark *mPlacemark = [[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil] autorelease];
[mapView addAnnotation:mPlacemark];
[mapView setRegion:thisRegion animated:YES];
Run Code Online (Sandbox Code Playgroud) iphone ×6
ios ×5
objective-c ×5
cocoa-touch ×2
arrays ×1
background ×1
build ×1
clgeocoder ×1
cllocation ×1
cocoa ×1
constants ×1
core-data ×1
geolocation ×1
global ×1
macos ×1
mkmapview ×1
mkplacemark ×1
nsinvocation ×1
nsoperation ×1
provisioning ×1
statusbar ×1
string ×1
title ×1
uikit ×1
uiview ×1
urlencode ×1
xcode ×1
xcode4 ×1