Permalink
Browse files

sanity check of the indexPath before insertion to prevent crashes

  • Loading branch information...
justadreamer committed Aug 19, 2015
1 parent 55fe505 commit 1d5994507fbb31083d45001f0ab2c948b8fde3e9
Showing with 10 additions and 0 deletions.
  1. +5 −0 MoPubSDK/Native Ads/MPCollectionViewAdPlacer.m
  2. +5 −0 MoPubSDK/Native Ads/MPTableViewAdPlacer.m
@@ -115,6 +115,11 @@ - (void)updateVisibleCells

- (void)adPlacer:(MPStreamAdPlacer *)adPlacer didLoadAdAtIndexPath:(NSIndexPath *)indexPath
{
if (!(indexPath.section<[self.collectionView numberOfSections] &&
indexPath.row<[self.collectionView numberOfItemsInSection:indexPath.section])) {
return;
}

BOOL animationsWereEnabled = [UIView areAnimationsEnabled];
//We only want to enable animations if the index path is before or within our visible cells
BOOL animationsEnabled = ([(NSIndexPath *)[self.collectionView.indexPathsForVisibleItems lastObject] compare:indexPath] != NSOrderedAscending) && animationsWereEnabled;
@@ -123,6 +123,11 @@ - (void)updateVisibleCells

- (void)adPlacer:(MPStreamAdPlacer *)adPlacer didLoadAdAtIndexPath:(NSIndexPath *)indexPath
{
if (!(indexPath.section<[self.tableView numberOfSections] &&
indexPath.row<[self.tableView numberOfRowsInSection:indexPath.section])) {
return;
}

BOOL originalAnimationsEnabled = [UIView areAnimationsEnabled];
//We only want to enable animations if the index path is before or within our visible cells
BOOL animationsEnabled = ([(NSIndexPath *)[self.tableView.indexPathsForVisibleRows lastObject] compare:indexPath] != NSOrderedAscending) && originalAnimationsEnabled;

0 comments on commit 1d59945

Please sign in to comment.