当我将我的应用程序测试为 DEBUG 时,它就可以了。但是当我发布到 App Store 并从 App Store 安装应用程序时,它会崩溃。
因此,我将 DEBUG RUN方法更改为 RELEASE 运行方法进行测试。
当我现在以 RELEASE 运行方法运行时,应用程序也会崩溃(与APP商店崩溃相同)。应用程序崩溃指向第19行。
我该如何解决?在这里,我告诉通过将一个字符串与第18行的字符串连接来制作DNS(A或AAAA记录)self.server = [self.server stringByAppendingString:@".example.com"];
。
- (void)myMethodHere:(NSString *)a {
//where a = @"splitme://test1/test2/test3";
NSArray *work_array = [a componentsSeparatedByString:@"splitme://"];
self.use_url =[work_array objectAtIndex:1];
if ([self.use_url length] > 0) {
NSArray *work_array = [self.use_url componentsSeparatedByString:@"/"];
self.server = [work_array objectAtIndex:0];
// -------------------
// CRASH HERE // CRASH HERE
// -------------------
if([self.server length] > 0) {
NSLog(@"!!!!!!!!!!!!!!!!!!!!!! 4 - part 1: %@", self.server); // WORKS
// Here we go CRASHing...
self.server = [self.server stringByAppendingString:@".example.com"];
NSLog(@"!!!!!!!!!!!!!!!!!!!!!! 4 - part 2: %@", self.server); // CRASH CRASH
}
else {
self.server = @"test.example.com";
}
}
else {
NSLog(@"!!!!!!!!!!!!!!!!!!!!!! 9: %@", self.use_url);
}
[self load_later];
}
编辑1:按照以下方式让我通过,但如果我再次拥有此范围之外的self.server,那么app会再次崩溃。
NSString *part1 = self.server;
NSString *part2 = @".example.com";
NSString *result =[part1 stringByAppendingString:part2];
self.server = result;
NSLog(@"!!!!!!!!!!!!!!!!!!!!!! 4 - part 2: %@", self.server);
在注释掉NSLog行后,编辑2:在AppDelegate.m上崩溃。
2017-04-08 10:32:01.773648+0200 app[344:18271] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2017-04-08 10:32:01.774146+0200 app[344:18271] [MC] Reading from public effective user settings.
2017-04-08 10:32:01.778647+0200 app[344:18271] -[__NSArrayM length]: unrecognized selector sent to instance 0x1740457c0
2017-04-08 10:32:01.778888+0200 app[344:18271] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM length]: unrecognized selector sent to instance 0x1740457c0'
*** First throw call stack:
(0x18a956fd8 0x1893b8538 0x18a95def4 0x18a95af4c 0x18a856d2c 0x100006f78 0x1000076e8 0x1000066cc 0x190a85f9c 0x190a85b78 0x190a8c3f8 0x190a89894 0x190afb2fc 0x190d038b4 0x190d092a8 0x190d1dde0 0x190d0653c 0x18c4ff884 0x18c4ff6f0 0x18c4ffaa0 0x18a905424 0x18a904d94 0x18a9029a0 0x18a832d94 0x190af045c 0x190aeb130 0x100007d78 0x18984159c)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
编辑3:即使使用显式强制转换,也会破坏NSString而不是NSString
- (void)setServer:(NSString *)value
{
if (value != nil && ![value isKindOfClass:[NSString class]]) {
NSLog(@"!!!!!!!!!!!lol!!!!!!!!!!!!! Bug! Set breakpoint here!");
}
self.server = value;
}
NSArray *work_array = [self.use_url componentsSeparatedByString:@"/"];
NSString *setServerURL =(NSString *) [work_array objectAtIndex:0];
[self setServer:setServerURL];
编辑4:崩溃
- (void)myMethodHere:(NSString *)a {
NSArray *work_array = [a componentsSeparatedByString:@"test://"];
id objectOne = [work_array objectAtIndex:1];
if ([objectOne isKindOfClass:[NSString class] ] ) {
NSString *objectOneIntoString = objectOne;
self.use_url = (NSString *) objectOneIntoString;
}
if ([self.use_url length] > 0) {
NSLog(@"3: %@", self.use_url);
NSArray *work_array = [self.use_url componentsSeparatedByString:@"/"];
id objectTwo = [work_array objectAtIndex:0];
if ([objectTwo isKindOfClass:[NSString class] ]) {
NSString *objectTwoIntoString = objectTwo;
self.server = objectTwoIntoString;
}
if([self.server length] > 0) {
NSLog(@"4 - part 1: %@", self.server);
NSString *part1 = self.server;
NSString *part2 = @".example.com";
NSString *result = (NSString *) [part1 stringByAppendingString:part2];
self.server = result;
NSLog(@"4 - part 2: %@", self.server);
}
else {
self.server = @"dns.example.com";
NSLog(@"5:%@", self.server);
}
NSLog(@"8: %@", self.server);
}
else {
NSLog(@"9: %@", self.use_url);
}
NSLog(@"10: %@", self.use_url);
}
答案 0 :(得分:3)
您的pastebin中的错误消息是:
2017-04-08 10:32:01.778647+0200 app[344:18271] -[__NSArrayM length]: unrecognized selector sent to instance 0x1740457c0
2017-04-08 10:32:01.778888+0200 app[344:18271] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM length]: unrecognized selector sent to instance 0x1740457c0'
这告诉您有一个数组,您调用了length
。因此,如果确实与您的server
属性相关,那么您偶然会在某处存储NSArray
。
以下是关于如何捕获它的想法:实现setServer:
方法并检查类型是否正确。
- (void)setServer:(NSString *)value
{
if (value != nil && ![value isKindOfClass:[NSString class]]) {
NSLog(@"Bug! Set breakpoint here!");
}
_server = value;
}
编辑:您错误地实现了您的setter,并且通常会产生无休止的递归。所以,让我们从头开始:
我假设您有一个如下定义的属性:
@property (strong) NSString * server; // Or maybe "copy"
如果你的财产不看起来像这样,你需要告诉我们!
然后你就像这样实现
。- (void)setServer:(NSString *)value
{
if (value != nil && ![value isKindOfClass:[NSString class]]) {
NSLog(@"Bug! Set breakpoint here!");
}
_server = value;
// DO NOT DO self.server = value HERE!
}
然后您可以在代码的其余部分中执行self.server = blabla;
,如果您的代码设置的内容不是字符串,则NSLog
将被命中。 所以在那里设置一个断点!
编辑2:
现在我已经在你的另一条评论中看到了什么错......
@property (assign, nonatomic) NSString *server;
assign
不保留对象!您需要使用strong
或(如果是NSString *
)copy
。实际情况如下:
server
。server
仍然有一个指向该内存位置的指针。现在可能发生两件事:
切勿将assign
与对象一起使用!
答案 1 :(得分:1)
- [__ NSArrayM长度]:无法识别的选择器发送到实例0x1740457c0
self.server类是NSArray。必须是字符串长度