2017-04-05 10 views
0

아바타의 원격 이미지를로드하려고하면 내 이미지를 사용할 수 없다는 오류 메시지와 함께 응용 프로그램이 다운됩니다. 단순히 앱이 성공 로그에 도착하기 전에 충돌한다원격 이미지로드 중 JSQMessagesAvatarImageFactory가 깨졌습니다.

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    self.inputToolbar.contentView.textView.pasteDelegate = self; 
    self.userAvatarDictionary = [[NSMutableDictionary alloc] init]; 
    self.latestGuid = @""; 

    /** 
    * Load up our fake data for the demo 
    */ 
    self.demoData = [[DemoModelData alloc] init]; 

    /** 
    * You can set custom avatar sizes 
    */ 

    self.collectionView.collectionViewLayout.incomingAvatarViewSize = CGSizeMake(30, 30); 

    self.collectionView.collectionViewLayout.outgoingAvatarViewSize = CGSizeZero; 

    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage jsq_defaultTypingIndicatorImage] 
                       style:UIBarButtonItemStylePlain 
                      target:self 
                      action:@selector(receiveMessagePressed:)]; 


    //Load remote image for Gibson Les Paul Guitar as test 
    NSString *imgURLString = @"http://images.gibson.com/Products/Electric-Guitars/Les-Paul/Gibson-USA/Les-Paul-Studio/Splash-02.jpg"; 

    NSURL *url = [NSURL URLWithString:imgURLString]; 
    NSLog(@"CREATED USER ID: 13"); 
    NSLog(@"CREATOR IMAGE URL: %@", imgURLString); 
    NSData *data = [NSData dataWithContentsOfURL:url]; 
    UIImage *dataLoadedImg = [UIImage imageWithData:data]; 


    JSQMessagesAvatarImage *img = [JSQMessagesAvatarImageFactory avatarImageWithImage:dataLoadedImg diameter:20.0f]; 

    [self.userAvatarDictionary setObject:img forKey:@"13"]; 
    NSLog(@"ADDED GIBSON ICON SUCCESSFULLY"); 
    [self callViewMessagesListWithLatestMessageGuid:self.latestGuid 
            CompletionBlock:^(NSMutableArray *resultsArray) { 
             [self reloadData:resultsArray]; 
            }]; 
    [NSTimer scheduledTimerWithTimeInterval:15.0 target:self selector:@selector(fifteenSecondsPassed:) userInfo:nil repeats:YES]; 
} 

를 당분간 내있는 viewDidLoad 방법에 아바타 생성을 추가하고, 분명히 메시지 로딩 웹 서비스 호출 받고 있지 않습니다.

Logging/Error messaging: 

CREATED USER ID: 13 
CREATOR IMAGE URL: http://images.gibson.com/Products/Electric-Guitars/Les-Paul/Gibson-USA/Les-Paul-Studio/Splash-02.jpg 

*** Assertion failure in +[JSQMessagesAvatarImageFactory jsq_circularImage:withDiameter:highlightedColor:], /Users/propstm/Documents/Github/MyProject/Pods/JSQMessagesViewController/JSQMessagesViewController/Factories/JSQMessagesAvatarImageFactory.m:132 
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: image != nil' 

답변

1

이미지가보기에 필요하지 않을 때로드되지 않았기 때문입니다. 이미지를 다시 얻을 수있을 때까지 기본 이미지를 사용하여 해결할 수 있습니다. 처음에 사용하는 기본 빈 아바타를 제공하는 방법을 만들면 요청이 반환되면 해당 셀에 대해 아바타가 업데이트됩니다. 당신이 대화에서 사용자 사전을 만든 다음 한 번만 요청을 할 필요를 위해 그 사전에서 뽑을 수 그들을 위해 원격 이미지를 얻을이 사전에 저장하는 경우 최적화로 또한

func getBlankAvatar() -> UIImage { 
    let blankAvatar = JSQMessagesAvatarImageFactory.avatarImageWithUserInitials("?", backgroundColor: .gray, textColor: .white, font: UIFont.systemFontOfSize(14), diameter: UInt(kJSQMessagesCollectionViewAvatarSizeDefault)) 

개별 메시지 셀

0

이미지를 다운로드해야 사용할 수 있습니다. SDWebImage을 사용하여 웹 이미지의 모든 작업을 처리 할 수 ​​있습니다. cocoapods로 SDWebImage를 설치 한 후 다음 코드를 추가하십시오.

[[SDWebImageManager sharedManager] downloadImageWithURL:imgURLString 
               options:0 
              progress:nil 
              completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { 
    if (!error && finished && image) { 
    [self.userAvatarDictionary setObject:image forKey:@"13"]; 
    NSLog(@"ADDED GIBSON ICON SUCCESSFULLY"); 
    [self.collectionView reloadData]; 
    } 
}];