xCode CGContextSaveGState:无效的上下文0x0错误

时间:2015-09-17 14:16:45

标签: ios objective-c cgcontext xcode7

我刚刚将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];
}

1 个答案:

答案 0 :(得分:-6)

按照link更正了我的错误。

我特别使用了这个:

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

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