IOS移动端怎么获取ArcGIS Server的服务
发布时间: 2012-09-19 13:43:54 作者: rapoo
IOS移动端如何获取ArcGIS Server的服务列表
1、应用需求
ArcGIS Server服务器增加、删除服务,移动端能动态的获取服务列表;
2、移动端解决方法
2.1、获取服务器端服务列表URL地址
(1)打开ArcGIS Server服务目录

(2)点击rest得到服务列表URL

(3)点击rest可以看到服务列表的json串,这个url就是我们获取服务列表的url

2.2 IOS读取方法
(1)异步调用服务
//服务URL
NSURL* url = [NSURL URLWithString:@"http://192.168.0.1/arcgis/rest/services?f=pjson"];
//self.currentJsonOp是 AGSJSONRequestOperation 对象self.currentJsonOp = [[[AGSJSONRequestOperation alloc]initWithURL:url]autorelease];
self.currentJsonOp.target = self;
self.currentJsonOp.action = @selector(operation:didSucceedWithResponse:);
self.currentJsonOp.errorAction = @selector(operation:didFailWithError:);
//self.queue 是 NSOperationQueue 对象
//Add operation to the queue to execute in the background
[self.queue addOperation:self.currentJsonOp];(2)处理调用结果,得到服务名称
//成功处理,The webservice was invoked successfully.
- (void)operation:(NSOperation*)op didSucceedWithResponse:(NSDictionary*)weatherInfo{
//Print the response to see what the JSON payload looks like.
NSLog(@"%@", weatherInfo);
NSLog(@"number is %d",weatherInfo.count);
if([weatherInfo objectForKey:@"services"]!=nil){
NSArray *servicesArray=[weatherInfo objectForKey:@"services"];
NSLog(@"%@,lenth is %d", servicesArray,[servicesArraycount]);
for (int i=0; i<[servicesArraycount];i++){
NSDictionary *services=[servicesArrayobjectAtIndex:i];
//NSLog(@"%@", services);
NSString *name=[servicesobjectForKey:@"name"];
NSString *type=[servicesobjectForKey:@"type"];
NSLog(@"%@,%@",name,type);
}
}
}
//处理失败,Error encountered while invoking webservice. Alert user
- (void)operation:(NSOperation*)op didFailWithError:(NSError *)error{
self.mapView.callout.hidden = YES;
UIAlertView* av = [[[UIAlertView alloc] initWithTitle:@"Sorry"
message:[error localizedDescription]
delegate:nil cancelButtonTitle:@"OK"
otherButtonTitles:nil] autorelease];
[av show];
}这样就动态的得到了地图服务的URL列表
