【问题标题】:xCode CGContextSaveGState: invalid context 0x0 ErrorxCode CGContextSaveGState:无效上下文 0x0 错误
【发布时间】:2015-12-14 11:00:16
【问题描述】:

我刚刚将 xCode 更新到 7.0。我的代码以前可以工作,但现在我得到了:

CGContextSaveGState:无效的上下文 0x0。如果要查看回溯,请设置 CG_CONTEXT_SHOW_BACKTRACE 环境变量。

在我的应用程序中,我有一个收件箱,一旦选择了消息单元格,就会显示图像/视频。在消息显示正常之前,但在更新后它们不再显示。这是一个有效的错误还是 Apple 错误?涉及的代码放在下面。

InboxTableViewController.m

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    self.selectedMessage = [self.messages objectAtIndex:indexPath.row];

    // mark message as read
    NSMutableArray *readByIds = [NSMutableArray arrayWithArray:[self.selectedMessage objectForKey:@"readBy"]];

    if ([readByIds containsObject:[[PFUser currentUser] objectId]]) {
        // message has already been read. do nothing
    }else {
        // message was unread. mark it as read now.
        [readByIds addObject:[[PFUser currentUser] objectId]];
        [self.selectedMessage setObject:readByIds forKey:@"readBy"];
        [self.selectedMessage saveInBackground];
    }


    NSString *fileType = [self.selectedMessage objectForKey:@"fileType"];
    if ([fileType isEqualToString:@"image"]) {
        // file type is image
        [self performSegueWithIdentifier:@"showImage" sender:self];
    } else {
        // file type is video
        PFFile *videoFile = [self.selectedMessage objectForKey:@"file"];
        NSURL *fileUrl = [NSURL URLWithString:videoFile.url];
        self.moviePlayer.contentURL = fileUrl;
        [self.moviePlayer prepareToPlay];
        [self.moviePlayer thumbnailImageAtTime:0 timeOption:MPMovieTimeOptionNearestKeyFrame];

        // add it to the view controller so we can see it
        [self.view addSubview:self.moviePlayer.view];
        [self.moviePlayer setFullscreen:YES animated:YES];
    }

}

...

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showLogin"]) {
        LoginViewController *lvc = (LoginViewController *)segue.destinationViewController;
        [lvc setHidesBottomBarWhenPushed:YES];
        lvc.navigationItem.hidesBackButton = YES;
        //[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
    } else if ([segue.identifier isEqualToString:@"showImage"]) {
        ImageViewController *ivc = (ImageViewController *)segue.destinationViewController;
        [ivc setHidesBottomBarWhenPushed:YES];
        ivc.message = self.selectedMessage;
    }
}

ImageViewController.m

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *senderName = [self.message objectForKey:@"senderFullName"];
    self.navigationItem.title = senderName;

    // download image from Parse.com
    PFFile *imageFile = [self.message objectForKey:@"file"];
    NSURL *imageFileUrl = [[NSURL alloc] initWithString:imageFile.url];
    NSData *imageData = [NSData dataWithContentsOfURL:imageFileUrl];

    //set the image view to the message image
    self.imageView.image = [UIImage imageWithData:imageData];
}

【问题讨论】:

  • 你试过设置CG_CONTEXT_SHOW_BACKTRACE变量吗?
  • 我该怎么做呢?
  • 这也可能是一个错误。见this。
  • 好的,谢谢。我报告了这个错误
  • 要设置 CG_CONTEXT_SHOW_BACKTRACE,请转到 Edit Schemes... > Run > Arguments > Environment Variables。添加值为 1 的变量 CG_CONTEXT_SHOW_BACKTRACE。

标签: ios objective-c cgcontext xcode7


【解决方案1】:

在此link 之后更正了我的错误。

我特别用过这个:

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

并在我的 info.plist 中设置这些值

【讨论】:

  • 这与 Graphichs 上下文有什么关系??
  • 这并不能回答所提出的实际问题,即关于图形上下文,而不是传输安全
猜你喜欢
  • 1970-01-01
  • 2015-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-30
  • 1970-01-01
相关资源
最近更新 更多