崩溃加载自定义NSBundle时崩溃

时间:2013-07-29 05:18:30

标签: ios crash nsbundle

大家好,我加载自定义NSBundle TicketBooking.bundle )时出现问题,APP崩溃了 (exited abnormally with signal 9: Killed: 9 EXC_CRASH (SIGKILL))。

最奇怪的是:
1.当我将iPhone 4连接到Mac时,从Xcode运行APP,调用方法[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];

0 个答案:

没有答案