簡體   English   中英

與直接構建到設備相比,Build&Archive / TestFlight中的行為不同

[英]Different behavior in Build & Archive / TestFlight than building directly to device

我最近在我的應用程序中添加了在表格單元格中長按UILabel的功能,以使“復制”菜單出現,以便用戶可以將文本復制到粘貼板。 無論是在模擬器中還是在直接構建到設備上時,它都能很好地工作。 但是,當我生成和存檔(以便可以推送到TestFlight)時,該功能不起作用。

我嘗試了這個Stack Overflow問題中的解決方案,但是它沒有用(並且似乎不相關,因為我正在為iOS 5.0+開發)。 我在構建設置中將優化級別設置為None [-O0]

  1. 如果在Xcode中可以正常工作,我該如何調試失敗的內容? (即,是手勢識別器不起作用,還是UIMenuController等?)
  2. 為什么存檔副本的行為與構建到設備的副本不同?

這是相關的代碼(盡管我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:) );
}

就像我說的那樣,它可以很好地在設備和模擬器中構建,而不僅僅是在Build&Archive之后。

在發布版本中未調用NSAssert方法,因為-DNS_BLOCK_ASSERTIONS標志已為發布版本啟用。

在上面的代碼中,我通過將[self becomeFirstResponder]移動到其自己的行,將返回值分配給BOOL,然后在BOOL上調用NSAssert來解決了該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM