我有这些方法从互联网上检索一些对象信息:
- (void)downloadAppInfo:(void(^)())success
failure:(void(^)(NSError *error))failure;
- (void)getAvailableHosts:(void(^)())success
failure:(void(^)(NSError *error))failure;
- (void)getAvailableServices:(void(^)())success
failure:(void(^)(NSError *error))failure;
- (void)getAvailableActions:(void(^)())success
failure:(void(^)(NSError *error))failure;
Run Code Online (Sandbox Code Playgroud)
下载的东西存储在对象属性中,这就是成功函数不返回任何内容的原因.
现在,我想要一个像这样的方法:
- (void)syncEverything:(void(^)())success
failure:(void(^)(NSError *error))failure;
Run Code Online (Sandbox Code Playgroud)
除了调用上面的所有方法之外,它只会在每个方法执行其成功或失败块之后返回.
我怎样才能做到这一点?
提示:我知道级联方法调用彼此成功块会起作用.但是,当后来的实现包括更多方法时,这既不"干净"也不有用.
尝试:
我尝试在a中运行每个调用NSOperation并将其添加NSOperations到a NSOperationQueue后跟"完成操作",这取决于前面的每个操作.
这不行.由于即使在各自的成功/失败块返回之前也认为操作已完成.
我也试过用dispatch_group.但我不清楚我是以正确的方式做到这一点.不幸的是,它没有用.
nsoperation nsoperationqueue grand-central-dispatch ios objective-c-blocks
反正手动启动/初始化通道适配器了吗?
我在context.xml中有两对入站/出站适配器,并希望在运行时决定我想要启动哪一个.
编辑:
具体方案:
我有一个客户端,可以在运行时配置为mqtt发布者或订阅者.
我的context.xml看起来像这样:
<int-mqtt:message-driven-channel-adapter
client-id="foo"
auto-startup="true"
url="tcp://192.168.97.164:1883"
topics="testtopic/#"
channel="writeToFile" />
<file:outbound-channel-adapter
id="writeToFile"
auto-startup="true"
directory="./test/out"
delete-source-files="false"/>
<int:transformer id="Transformer"
ref="MessageTransformer"
input-channel="readFromFile"
output-channel="mqttOut"
method="bytesFromFile" />
<bean id="MessageTransformer" class="MessageTransformer"/>
<int-mqtt:outbound-channel-adapter
id="mqttOut"
client-id="foo"
url="tcp://192.168.97.164:1883"
auto-startup="false"
default-qos="1"
default-retained="true"
default-topic="testtopic/bla"
/>
<file:inbound-channel-adapter
auto-startup="false"
id="readFromFile"
directory="./test/in"
filename-pattern="myFile*">
<int:poller id="poller"
fixed-rate="5000" />
</file:inbound-channel-adapter>
Run Code Online (Sandbox Code Playgroud)
如您所见,我有两个设置:
1.订阅者案例:读取mqtt消息 - >写入文件
2.发布者案例:从目录中轮询文件 - >通过mqtt发送
我在运行时决定应用什么设置.
那么请你告诉我这个控制总线的东西究竟适合这里吗?
如何获取CGPDFObject的ID?
我的PDF中有这本字典:
3 0 obj
<< /Type /Pages /MediaBox [0 0 612 792] /Count 5 /Kids [ 2 0 R 9 0 R 15 0 R
21 0 R 27 0 R ] >>
endobj
Run Code Online (Sandbox Code Playgroud)
我用它来获得:
CGPDFDictionaryRef pdfPagesObjectRef;
CGPDFDictionaryGetDictionary(pdfCatalogueRef, "Pages", &pdfPagesObjectRef);
Run Code Online (Sandbox Code Playgroud)
现在我知道CGPDFDictionaryApplyFunction要在字典中获取键/值对.但是如何获得自己的对象ID和代数?(在这种情况下为3和0).
编辑:为什么我需要这些信息?我正在尝试向文件添加文本注释.根据我的理解,在iOS中没有"高级"方法.您必须手动附加新部分(外部参照表,重写对象,预告片等).因此,不可避免地要获取我想要覆盖的对象的ID和世代号,以及我覆盖的对象中引用的那些(例如,/ Resources,/被覆盖页面中的内容).
我真的想通过这样评论来临时启用和禁用代码部分:
/*
some code
/**/
Run Code Online (Sandbox Code Playgroud)
(记住
/**/
代替
*/
在末尾)
但是,XCode不断给我警告:
/* within block comment
Run Code Online (Sandbox Code Playgroud)
有没有办法"自定义禁用"特定警告?
为什么?我会告诉你原因:因为我只需要一个字符就可以很容易地进出,而不必向下滚动块来取出"*/in和out".
如果没有阅读整个问题,请不要标记为重复
有没有办法在iOS中的两点之间获得驱动路线的长度CLLocation,而不显示地图?
不像乌鸦飞!但就像在MK驾驶模式中一样
我不能使用谷歌,因为我必须在谷歌地图上显示结果.
我找到了这段代码,但这仅在显示iOS-Map时有效:
-(void)showMapRouteFromCurrentLocation
{
CLLocationCoordinate2D currentUserCoordinate = YourCoordinate;
//currentUserCoordinate.latitude= +53.509980;
//currentUserCoordinate.longitude = -0.133700;
MKPlacemark *place = [[MKPlacemark alloc]
initWithCoordinate:currentUserCoordinate
addressDictionary:nil];
MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:place];
NSDictionary *routeOption = [[NSDictionary alloc] initWithObjectsAndKeys:MKLaunchOptionsDirectionsModeDriving,MKLaunchOptionsDirectionsModeKey, nil];
[mapItem openInMapsWithLaunchOptions:routeOption];
}
Run Code Online (Sandbox Code Playgroud)
但这不是我需要的.
编译Microsoft(VS 2012 RC)提供的任何Win 8 Metro样式应用程序示例时,我遇到了这种错误:
错误1源文件'C:\ Users\me\Desktop\Windows 8发布预览Metro风格应用示例 - C#,VB.NET,C++,JavaScript\XAML图像示例\ C#\ obj\Release\App.gics'不能是发现C:\ Users\me\Desktop\Windows 8发布预览Metro风格应用示例 - C%23%2c VB.NET%2c C%2b%2b%2c JavaScript\XAML图像示例\ C#\ CSC图像
错误2源文件'C:\ Users\me\Desktop\Windows 8发布预览Metro风格应用示例 - C#,VB.NET,C++,JavaScript\XAML图像示例\ C#\ obj\Release\App.g.cs'可以找不到C:\ Users\me\Desktop\Windows 8 Release Preview Metro风格应用示例 - C%23%2c VB.NET%2c C%2b%2b%2c JavaScript\XAML图像示例\ C#\ CSC图像
知道我做错了什么吗?
这段代码:
NSString *urlPath = [[NSBundle mainBundle] pathForResource:@"snd" ofType:@"mp3"];
NSURL *url = [NSURL fileURLWithPath:urlPath];
NSError *err;
AVAudioPlayer* audioPlayerMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&err];
[audioPlayerMusic play];
Run Code Online (Sandbox Code Playgroud)
工作得很好.
这一个:
NSString *urlPath = [[NSBundle mainBundle] pathForResource:@"snd" ofType:@"mp3"];
NSURL *url = [NSURL fileURLWithPath:urlPath];
AVPlayer* audioPlayerMusic = [AVPlayer playerWithURL:url];
[audioPlayerMusic play];
Run Code Online (Sandbox Code Playgroud)
什么都不玩!
出了什么问题?
我正在ARC自动转换项目中工作.
我有一个巨大的文本文件(14MB)的内容存储在NSString *_documentDataString.
现在我有这个循环:
- (void)scanParts
{
NSString *boundary = [boundaryPrefix stringByAppendingString:_header.boundary];
NSMutableArray *parts = [NSMutableArray array];
NSInteger currentLocation = [_documentDataString rangeOfString:boundary].location;
BOOL reachedTheEnd = NO;
while(!reachedTheEnd)
{
NSInteger nextBoundaryLocation = [[_documentDataString substringFromIndex:currentLocation + 1]
rangeOfString:boundary].location;
if(nextBoundaryLocation == NSNotFound)
{
reachedTheEnd = YES;
}
else
{
nextBoundaryLocation += currentLocation + 1;
//[parts addObject:[_documentDataString substringWithRange:
// NSMakeRange(currentLocation, nextBoundaryLocation - currentLocation)]];
currentLocation = nextBoundaryLocation;
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我开始收到这些错误:
malloc: *** mmap(size=6496256) failed (error code=12)
*** error: can't allocate region
*** …Run Code Online (Sandbox Code Playgroud) 用字符串中的'X'替换小写字符的最干净,最Pythonic的代码是什么?例如,ABCDEFGhijklmnopQRSTUVwxyz会成为ABCDEFGXXXXXXXXXQRSTUVXXXX.