From eec8ff42360117a68c44e73ac7dbe7c1e39547c8 Mon Sep 17 00:00:00 2001 From: Jesse Squires Date: Sat, 10 Jan 2015 15:22:22 -0800 Subject: [PATCH] remove references to main bundle for cocoapods 0.36. close #698. --- .../JSQSystemSoundPlayer+JSQMessages.m | 44 ++++++++++++++----- .../Categories/UIImage+JSQMessages.m | 6 ++- .../Controllers/JSQMessagesViewController.m | 4 +- .../Views/JSQMessagesCollectionViewCell.m | 2 +- .../Views/JSQMessagesInputToolbar.m | 4 +- .../Views/JSQMessagesLoadEarlierHeaderView.m | 2 +- .../Views/JSQMessagesToolbarContentView.m | 2 +- .../JSQMessagesTypingIndicatorFooterView.m | 2 +- 8 files changed, 48 insertions(+), 18 deletions(-) diff --git a/JSQMessagesViewController/Categories/JSQSystemSoundPlayer+JSQMessages.m b/JSQMessagesViewController/Categories/JSQSystemSoundPlayer+JSQMessages.m index 8100a286a..75714e834 100644 --- a/JSQMessagesViewController/Categories/JSQSystemSoundPlayer+JSQMessages.m +++ b/JSQMessagesViewController/Categories/JSQSystemSoundPlayer+JSQMessages.m @@ -18,34 +18,58 @@ #import "JSQSystemSoundPlayer+JSQMessages.h" -static NSString * const kJSQMessageReceivedSoundName = @"JSQMessagesAssets.bundle/Sounds/message_received"; -static NSString * const kJSQMessageSentSoundName = @"JSQMessagesAssets.bundle/Sounds/message_sent"; +#import "JSQMessagesViewController.h" + + +static NSString * const kJSQMessageReceivedSoundName = @"message_received"; +static NSString * const kJSQMessageSentSoundName = @"message_sent"; @implementation JSQSystemSoundPlayer (JSQMessages) +#pragma mark - Public + + (void)jsq_playMessageReceivedSound { - [[JSQSystemSoundPlayer sharedPlayer] playSoundWithFilename:kJSQMessageReceivedSoundName - fileExtension:kJSQSystemSoundTypeAIFF]; + [self jsq_playSoundFromJSQMessagesBundleWithName:kJSQMessageReceivedSoundName asAlert:NO]; } + (void)jsq_playMessageReceivedAlert { - [[JSQSystemSoundPlayer sharedPlayer] playAlertSoundWithFilename:kJSQMessageReceivedSoundName - fileExtension:kJSQSystemSoundTypeAIFF]; + [self jsq_playSoundFromJSQMessagesBundleWithName:kJSQMessageReceivedSoundName asAlert:YES]; } + (void)jsq_playMessageSentSound { - [[JSQSystemSoundPlayer sharedPlayer] playSoundWithFilename:kJSQMessageSentSoundName - fileExtension:kJSQSystemSoundTypeAIFF]; + [self jsq_playSoundFromJSQMessagesBundleWithName:kJSQMessageSentSoundName asAlert:NO]; } + (void)jsq_playMessageSentAlert { - [[JSQSystemSoundPlayer sharedPlayer] playAlertSoundWithFilename:kJSQMessageSentSoundName - fileExtension:kJSQSystemSoundTypeAIFF]; + [self jsq_playSoundFromJSQMessagesBundleWithName:kJSQMessageSentSoundName asAlert:YES]; +} + +#pragma mark - Private + ++ (void)jsq_playSoundFromJSQMessagesBundleWithName:(NSString *)soundName asAlert:(BOOL)asAlert +{ + // save sound player original bundle + NSString *originalPlayerBundleIdentifier = [JSQSystemSoundPlayer sharedPlayer].bundle.bundleIdentifier; + + // search for sounds in this library's bundle + [JSQSystemSoundPlayer sharedPlayer].bundle = [NSBundle bundleForClass:[JSQMessagesViewController class]]; + + NSString *fileName = [NSString stringWithFormat:@"JSQMessagesAssets.bundle/Sounds/%@", soundName]; + + if (asAlert) { + [[JSQSystemSoundPlayer sharedPlayer] playAlertSoundWithFilename:fileName fileExtension:kJSQSystemSoundTypeAIFF]; + } + else { + [[JSQSystemSoundPlayer sharedPlayer] playSoundWithFilename:fileName fileExtension:kJSQSystemSoundTypeAIFF]; + } + + // restore original bundle + [JSQSystemSoundPlayer sharedPlayer].bundle = [NSBundle bundleWithIdentifier:originalPlayerBundleIdentifier]; } @end diff --git a/JSQMessagesViewController/Categories/UIImage+JSQMessages.m b/JSQMessagesViewController/Categories/UIImage+JSQMessages.m index a55d54c93..55a6e28fd 100644 --- a/JSQMessagesViewController/Categories/UIImage+JSQMessages.m +++ b/JSQMessagesViewController/Categories/UIImage+JSQMessages.m @@ -18,6 +18,9 @@ #import "UIImage+JSQMessages.h" +#import "JSQMessagesViewController.h" + + @implementation UIImage (JSQMessages) - (UIImage *)jsq_imageMaskedWithColor:(UIColor *)maskColor @@ -47,7 +50,8 @@ - (UIImage *)jsq_imageMaskedWithColor:(UIColor *)maskColor + (UIImage *)jsq_bubbleImageFromBundleWithName:(NSString *)name { - return [UIImage imageNamed:[NSString stringWithFormat:@"JSQMessagesAssets.bundle/Images/%@", name]]; + return [UIImage imageNamed:[NSString stringWithFormat:@"JSQMessagesAssets.bundle/Images/%@", name] + inBundle:[NSBundle bundleForClass:[JSQMessagesViewController class]] compatibleWithTraitCollection:nil]; } + (UIImage *)jsq_bubbleRegularImage diff --git a/JSQMessagesViewController/Controllers/JSQMessagesViewController.m b/JSQMessagesViewController/Controllers/JSQMessagesViewController.m index 38af74398..436e8e594 100644 --- a/JSQMessagesViewController/Controllers/JSQMessagesViewController.m +++ b/JSQMessagesViewController/Controllers/JSQMessagesViewController.m @@ -105,13 +105,13 @@ @implementation JSQMessagesViewController + (UINib *)nib { return [UINib nibWithNibName:NSStringFromClass([JSQMessagesViewController class]) - bundle:[NSBundle mainBundle]]; + bundle:[NSBundle bundleForClass:[self class]]]; } + (instancetype)messagesViewController { return [[[self class] alloc] initWithNibName:NSStringFromClass([JSQMessagesViewController class]) - bundle:[NSBundle mainBundle]]; + bundle:[NSBundle bundleForClass:[self class]]]; } #pragma mark - Initialization diff --git a/JSQMessagesViewController/Views/JSQMessagesCollectionViewCell.m b/JSQMessagesViewController/Views/JSQMessagesCollectionViewCell.m index 51eb54054..69976a8d7 100644 --- a/JSQMessagesViewController/Views/JSQMessagesCollectionViewCell.m +++ b/JSQMessagesViewController/Views/JSQMessagesCollectionViewCell.m @@ -73,7 +73,7 @@ @implementation JSQMessagesCollectionViewCell + (UINib *)nib { - return [UINib nibWithNibName:NSStringFromClass([self class]) bundle:[NSBundle mainBundle]]; + return [UINib nibWithNibName:NSStringFromClass([self class]) bundle:[NSBundle bundleForClass:[self class]]]; } + (NSString *)cellReuseIdentifier diff --git a/JSQMessagesViewController/Views/JSQMessagesInputToolbar.m b/JSQMessagesViewController/Views/JSQMessagesInputToolbar.m index ff7287112..9ef5db83c 100644 --- a/JSQMessagesViewController/Views/JSQMessagesInputToolbar.m +++ b/JSQMessagesViewController/Views/JSQMessagesInputToolbar.m @@ -57,7 +57,9 @@ - (void)awakeFromNib self.jsq_isObserving = NO; self.sendButtonOnRight = YES; - NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([JSQMessagesToolbarContentView class]) owner:nil options:nil]; + NSArray *nibViews = [[NSBundle bundleForClass:[self class]] loadNibNamed:NSStringFromClass([JSQMessagesToolbarContentView class]) + owner:nil + options:nil]; JSQMessagesToolbarContentView *toolbarContentView = [nibViews firstObject]; toolbarContentView.frame = self.frame; [self addSubview:toolbarContentView]; diff --git a/JSQMessagesViewController/Views/JSQMessagesLoadEarlierHeaderView.m b/JSQMessagesViewController/Views/JSQMessagesLoadEarlierHeaderView.m index 6ef52aeac..cfbd136d0 100644 --- a/JSQMessagesViewController/Views/JSQMessagesLoadEarlierHeaderView.m +++ b/JSQMessagesViewController/Views/JSQMessagesLoadEarlierHeaderView.m @@ -39,7 +39,7 @@ @implementation JSQMessagesLoadEarlierHeaderView + (UINib *)nib { return [UINib nibWithNibName:NSStringFromClass([JSQMessagesLoadEarlierHeaderView class]) - bundle:[NSBundle mainBundle]]; + bundle:[NSBundle bundleForClass:[JSQMessagesLoadEarlierHeaderView class]]]; } + (NSString *)headerReuseIdentifier diff --git a/JSQMessagesViewController/Views/JSQMessagesToolbarContentView.m b/JSQMessagesViewController/Views/JSQMessagesToolbarContentView.m index 01cee9516..117aca2a4 100644 --- a/JSQMessagesViewController/Views/JSQMessagesToolbarContentView.m +++ b/JSQMessagesViewController/Views/JSQMessagesToolbarContentView.m @@ -47,7 +47,7 @@ @implementation JSQMessagesToolbarContentView + (UINib *)nib { return [UINib nibWithNibName:NSStringFromClass([JSQMessagesToolbarContentView class]) - bundle:[NSBundle mainBundle]]; + bundle:[NSBundle bundleForClass:[JSQMessagesToolbarContentView class]]]; } #pragma mark - Initialization diff --git a/JSQMessagesViewController/Views/JSQMessagesTypingIndicatorFooterView.m b/JSQMessagesViewController/Views/JSQMessagesTypingIndicatorFooterView.m index 107c9e4f8..098d7e2d4 100644 --- a/JSQMessagesViewController/Views/JSQMessagesTypingIndicatorFooterView.m +++ b/JSQMessagesViewController/Views/JSQMessagesTypingIndicatorFooterView.m @@ -44,7 +44,7 @@ @implementation JSQMessagesTypingIndicatorFooterView + (UINib *)nib { return [UINib nibWithNibName:NSStringFromClass([JSQMessagesTypingIndicatorFooterView class]) - bundle:[NSBundle mainBundle]]; + bundle:[NSBundle bundleForClass:[JSQMessagesTypingIndicatorFooterView class]]]; } + (NSString *)footerReuseIdentifier