1

大家好,我在加载自定义NSBundleTicketBooking.bundle)时遇到问题,APP 崩溃
exited abnormally with signal 9: Killed: 9 EXC_CRASH (SIGKILL))。

最奇怪的是:
1.当我将iPhone 4 连接到Mac 时,运行APP 从Xcode,调用方法[TicketBooking load][TicketBooking principalClass],返回正确的数据,APP 运行正常;
2.然后我将iPhone 4与Mac断开连接,按下APP,在方法[TicketBooking load]或运行时[TicketBooking principalClass],APP立即崩溃;

PS:TicketBooking.bundle 只包含两个类,CO_ManageVC.hCO_ManageVC.m

CO_ManageVC.h:

#import <UIKit/UIKit.h>

@interface CO_ManageVC : UIViewController

- (NSString *)TestWithKey:(NSString *)key;

@end

CO_ManageVC.m:

- (NSString *)TestWithKey:(NSString *)key{
    if ([key isEqualToString:@"tinln"])
        return @"CN_North";
    else {
        NSLog(@"Get CONamePrefix error:Wrong key");
        return nil;
}

当我打电话时:

NSBundle *TBBundle = [NSBundle bundleWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/TicketBooking.bundle"]];
//    NSLog(@"%@",[NSBundle allBundles]);
    NSLog(@"%@",[TBBundle infoDictionary]);
    if (TBBundle)
        NSLog(@"打开-done");
    else {
        NSLog(@"打开-fail");
        return;
    }
    NSLog(@"ready crash");
    //        [TBBundle load];  //disconnect and run,crash here
    Class TBClass = [TBBundle principalClass];   //disconnect and run,crash here
//        Class TBClass = [TBBundle classNamed:@"CO_ManageVC"]; ////disconnect and run,crash here
    UIViewController *tempVC = [[TBClass alloc] init];
    NSString *COStr = [tempVC performSelector:NSSelectorFromString(@"TestWithKey:") withObject:@"tinln"];
    NSLog(@"data:%@",COStr);    //when connect and run with xcode, NSLog return:data:CN_North
    [self.navigationController pushViewController:tempVC animated:YES];
    [tempVC release];
4

0 回答 0