动态地加载Reveal库意味着您可以控制Reveal服务的启动和停止。请先将libReveal.dylib加载入您的iOS应用,再参考以下步骤。
如果libReveal.dylib已被载入,那么在应用启动时,NSApplicationDidFinishLaunching
通知分发之后,Reveal服务就会自动启动。
您也可以选择通过分发一个名为IBARevealRequestStart
的NSNotification
,以手动的方式来启动服务:
Swift:
func startReveal() {
NSNotificationCenter.defaultCenter().postNotificationName("IBARevealRequestStart", object: nil)
}
Objective-C:
- (void)startReveal
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStart" object:nil];
}
倘若您不想修改应用程序的代码,也可以通过LLDB来分发同样的通知:
Swift:
expr NSNotificationCenter.defaultCenter().postNotificationName("IBARevealRequestStart", object: nil)
Objective-C:
expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStart" object:nil]
当通知分发之后,如果服务器正常启动,Xcode控制台则会输出类似下面的信息:
2015-01-20 16:07:59.474 Soundstagram[91612:9277015] INFO: Reveal Server started (Protocol Version 17).
如果libReveal.dylib已然被加载,那么同样也可以通过分发一个名为 IBARevealRequestStop
的 NSNotification
来手动地停止Reveal服务:
Swift:
func stopReveal() {
NSNotificationCenter.defaultCenter().postNotificationName("IBARevealRequestStop", object: nil)
}
Objective-C:
- (void)stopReveal
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStop" object:nil];
}
倘若您不想修改应用程序的代码,也可以通过LLDB来分发同样的通知:
Swift:
expr NSNotificationCenter.defaultCenter().postNotificationName("IBARevealRequestStop", object: nil)
Objective-C:
expr (void)[(NSNotificationCenter*)[NSNotificationCenter defaultCenter] postNotificationName:@"IBARevealRequestStop" object:nil]
当通知分发之后,如果服务器正常启动,Xcode控制台则会输出类似下面的信息:
2015-01-20 16:07:59.474 Soundstagram[13320:11275032] INFO: Reveal Server stopped.
当调试Swift项目时,LLDB要求所有传入expr
的命令都是Swift代码,但仅在当前调用栈的上下文也在Swift上下文中时才有此要求,比如,您在Swift代码中设置了一个断点。所以其他情况,expr
仍是要求使用Objective-C代码。
如果您希望通过调试器指令的方式,来在Swift工程中启动停止Reveal服务。请确认所使用的代码片段和断点所处的上下文在语言上是一致的。
如果您遇到任何Reveal集成的相关问题,请移步至我们的支持站点來寻求帮助。