我有一个我开发的 IOS 应用程序,当通过 xCode 部署时,它在模拟器和我的IPOD touch 上运行良好。我试图通过 TestFlight 与测试人员分享它;但应用程序总是遇到 SIGSEGV 异常。当我通过 TestFlight 加载应用程序时,我的 IPOD 触摸发生了同样的异常;但当我在我的IPOD touch上通过xCode运行应用程序时不会。
我已尽力追踪问题并使用远程日志记录并确定了失败的代码行;我不清楚它为什么会失败,我能做些什么,以及为什么它可以通过 xCode 而不是 TestFlight。
这是注销放置:
2012-09-16 14:46:41 TestFlight: Crash Handlers are installed
2012-09-16 14:46:41 Bootstrap
2012-09-16 14:46:41 bind settingsLoaded
2012-09-16 14:46:41 adding listeners to map
2012-09-16 14:46:41 listener map {
settingsLoaded = "{(\n)}";
}
2012-09-16 14:46:41 Loading appModel
2012-09-16 14:46:41 Loading settings
2012-09-16 14:46:41 Waiting for data to load
2012-09-16 14:46:42 TestFlight: Team Token is recognized
2012-09-16 14:46:42 Loading settings content
2012-09-16 14:46:42 Loading startScreen
2012-09-16 14:46:42 Loading jpegQuality
2012-09-16 14:46:42 Loading paperSize
2012-09-16 14:46:42 Loading showGrid
2012-09-16 14:46:42 Loading cropMode
2012-09-16 14:46:42 Loading filterType
2012-09-16 14:46:42 Loading adjustAllPages
2012-09-16 14:46:42 Loading settings complete
2012-09-16 14:46:42 triggering settings loaded
2012-09-16 14:46:42 trigger settingsLoaded
2012-09-16 14:46:42 triggerEvent settingsLoaded
2012-09-16 14:46:42 getting listeners from map
这是我失败的类的头文件
#import <Foundation/Foundation.h>
#import "Gritz.h"
@interface GritzObject : NSObject {
NSMutableDictionary *listenerMap;
}
#pragma creation
+ (GritzEvent*) create;
#pragma Events
- (void) bind:(void (^)(GritzEvent*))listener forEvent:(NSString*)name;
- (void) unbind:(void (^)(GritzEvent*))listener forEvent:(NSString*)name;
- (void) trigger:(NSString*)name;
- (void) triggerEvent:(GritzEvent*)event;
@end
这是失败的类的实现文件
#import "GritzObject.h"
#import "TestFlight.h"
@implementation GritzObject
#pragma create
+ (GritzObject *)create {
return [[GritzObject alloc] init];
}
- (id)init {
self = [super init];
if(self) {
listenerMap = [[NSMutableDictionary alloc] init];
}
return self;
}
#pragma events
- (void)bind:(void (^)(GritzEvent*))listener forEvent:(NSString *)name {
TFLog(@"bind %@", name);
NSMutableSet* listeners = [listenerMap objectForKey:name];
if(nil == listeners) {
TFLog(@"adding listeners to map");
listeners = [[NSMutableSet alloc] init];
[listenerMap setValue:listeners forKey:name];
TFLog(@"listener map %@", listenerMap);
}
[listeners addObject:listener];
}
- (void)unbind:(void (^)(GritzEvent*))listener forEvent:(NSString *)name {
TFLog(@"unbind %@", name);
NSMutableSet* listeners = [listenerMap objectForKey:name];
if(nil != listeners) {
[listeners removeObject:listener];
}
}
- (void)trigger:(NSString *)name {
TFLog(@"trigger %@", name);
[self triggerEvent:[GritzEvent withName:name]];
}
- (void)triggerEvent:(GritzEvent *)event {
TFLog(@"triggerEvent %@", event.name);
TFLog(@"getting listeners from map");
TFLog(@"listener map %@", listenerMap); // This throws a SIGSEGV exception
NSMutableSet* listeners = [listenerMap objectForKey:event.name];
TFLog(@"inspecting listeners array");
if(nil != listeners) {
for (void (^listener)(GritzEvent*) in listeners) {
listener(event);
}
}
else {
TFLog(@"no listeners found for event %@", event.name);
}
}
@end
从日志语句中我可以看出,尝试访问listnerMap 时会发生异常。看起来这个变量正在被取消引用;但目前尚不清楚为什么或我能做些什么?
我正在为这个应用程序使用 ARC。