objective-c - Build & Archive/TestFlight 中的不同行为与直接构建到设备

标签 objective-c ios xcode ios-simulator testflight

我最近在我的应用程序中添加了长按表格单元格内的 UILabel 以显示“复制”菜单的功能,以便用户可以将文本复制到粘贴板。它在模拟器中和我直接构建到设备时都很好用。但是,当我构建和存档(以便我可以推送到 TestFlight)时,该功能不起作用。

我尝试了 this Stack Overflow question 中的解决方案但它没有用(而且似乎不相关,因为我正在为 iOS 5.0+ 构建)。我在build设置中将优化级别设置为无[-O0]

  1. 如果它在 Xcode 中运行良好,我该如何调试失败的地方? (IE,是手势识别器不工作,还是 UIMenuController 等)
  2. 为什么 Archive 副本的行为与 build-to-device 副本不同?

这是相关代码(虽然我 90% 确定问题不是这段代码而是一些 Xcode 设置):

添加手势识别器:

UIGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
                                              initWithTarget:self action:@selector(handleLongPressForCopy:)];
[_postLabel addGestureRecognizer:longPress];            
[self addSubview:_postLabel];

处理长按

- (void)handleLongPressForCopy:(UILongPressGestureRecognizer *)recognizer {
    switch (recognizer.state) {
        case UIGestureRecognizerStateBegan:            
            NSAssert([self becomeFirstResponder], @"Sorry, UIMenuController will not work with %@ since it cannot become first responder", self);
            UIMenuController *theMenu = [UIMenuController sharedMenuController];
            CGRect displayRect = CGRectMake(_postLabel.frame.origin.x, _postLabel.frame.origin.y, 10, 0);
            [theMenu setTargetRect:displayRect inView:self];
            [theMenu setMenuVisible:YES animated:YES];

            break;
        default:
            break;
    }

}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    return (action == @selector(copy:) );
}

正如我所说,它在设备和模拟器中的构建效果很好,只是在构建和存档之后没有。

最佳答案

在发布版本中未调用 NSAssert 方法,因为为发布版本启用了 -DNS_BLOCK_ASSERTIONS 标志。

在上面的代码中,我通过将 [self becomeFirstResponder] 移动到它自己的行,将返回值分配给 BOOL,然后在 BOOL 上调用 NSAssert 来解决这个问题。

关于objective-c - Build & Archive/TestFlight 中的不同行为与直接构建到设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13313621/

相关文章:

iphone - 嵌套的 UINavigationControllers

ios - xCode 6.3.1 在模拟器上运行时缺少引用

ios - 如何在运行时更改约束优先级

iOS:将异步调用包装在方法中

ios - NSRegularExpression 验证电子邮件

ios - 为 Swift 2 更新 Alalmofire 和 SwiftyJSON

iphone - MPMoviePlayerController 存在黑色背景

python - 在 Objective-C NSMutableArray 中等效于 Python 的 `dict.get(' key', None)`?

ios - NSTimer 与 NSUserDefaults

iphone - 报亭应用后端