Skip to content

Commit

Permalink
MS-531 MRAID video does not launch correctly
Browse files Browse the repository at this point in the history
Added displayController to protocol for presenting playVideo
  • Loading branch information
Mark Ha committed Feb 6, 2014
1 parent 0251fdf commit 72aa3b0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 36 deletions.
29 changes: 1 addition & 28 deletions sdk/internal/ANAdView.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ @implementation ANAdView

// MRAIDAdViewDelegate methods
- (NSString *)adType { return nil; }
- (UIViewController *)displayController { return nil; }
- (void)adShouldResetToDefault {}
- (void)adShouldExpandToFrame:(CGRect)frame closeButton:(UIButton *)closeButton {}
- (void)adShouldResizeToFrame:(CGRect)frame allowOffscreen:(BOOL)allowOffscreen
Expand Down Expand Up @@ -189,16 +190,6 @@ - (void)mraidExpandAd:(CGSize)size

[self adWillPresent];

// set presenting controller for MRAID WebViewController
ANMRAIDAdWebViewController *mraidWebViewController;
if ([contentView isKindOfClass:[UIWebView class]]) {
UIWebView *webView = (UIWebView *)contentView;
if ([webView.delegate isKindOfClass:[ANMRAIDAdWebViewController class]]) {
mraidWebViewController = (ANMRAIDAdWebViewController *)webView.delegate;
mraidWebViewController.controller = rootViewController;
}
}

// set default frames for resetting later
if (CGRectIsNull(self.defaultFrame)) {
self.defaultParentFrame = defaultParentView.frame;
Expand All @@ -217,14 +208,6 @@ - (void)mraidExpandAd:(CGSize)size

self.mraidController.contentView = contentView;
[self.mraidController.view addSubview:contentView];
// set presenting controller for MRAID WebViewController
if ([contentView isKindOfClass:[UIWebView class]]) {
UIWebView *webView = (UIWebView *)contentView;
if ([webView.delegate isKindOfClass:[ANMRAIDAdWebViewController class]]) {
ANMRAIDAdWebViewController *webViewController = (ANMRAIDAdWebViewController *)webView.delegate;
webViewController.controller = self.mraidController;
}
}

[rootViewController presentViewController:self.mraidController animated:NO completion:^{
[self adDidPresent];
Expand Down Expand Up @@ -281,16 +264,6 @@ - (NSString *)mraidResizeAd:(CGRect)frame
NSString *mraidResizeErrorString = [self isResizeValid:contentView frameToResizeTo:frame];
if ([mraidResizeErrorString length] > 0) return mraidResizeErrorString;

// set presenting controller for MRAID WebViewController
ANMRAIDAdWebViewController *mraidWebViewController;
if ([contentView isKindOfClass:[UIWebView class]]) {
UIWebView *webView = (UIWebView *)contentView;
if ([webView.delegate isKindOfClass:[ANMRAIDAdWebViewController class]]) {
mraidWebViewController = (ANMRAIDAdWebViewController *)webView.delegate;
mraidWebViewController.controller = rootViewController;
}
}

// set default frames for resetting later
if (CGRectIsNull(self.defaultFrame)) {
self.defaultParentFrame = defaultParentView.frame;
Expand Down
2 changes: 1 addition & 1 deletion sdk/internal/ANAdWebViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
@interface ANMRAIDAdWebViewController : ANAdWebViewController <ANMRAIDEventReceiver>

@property (nonatomic, readwrite, weak) id<ANMRAIDAdViewDelegate> mraidDelegate;
@property (nonatomic, readwrite, weak) UIViewController *controller;

@end
9 changes: 2 additions & 7 deletions sdk/internal/ANAdWebViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,7 @@ - (void)dealloc {
if (self.viewabilityTimer) {
[self.viewabilityTimer invalidate];
}
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIApplicationDidEnterBackgroundNotification
object:[UIApplication sharedApplication]];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIApplicationDidChangeStatusBarOrientationNotification
object:[UIApplication sharedApplication]];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (BOOL)getWebViewVisible {
Expand Down Expand Up @@ -455,7 +450,7 @@ - (void)playVideo:(NSDictionary *)queryComponents {
object:moviePlayerViewController.moviePlayer];

[moviePlayerViewController.moviePlayer prepareToPlay];
[self.controller presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
[[self.mraidDelegate displayController] presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
[moviePlayerViewController.moviePlayer play];
}

Expand Down
4 changes: 4 additions & 0 deletions sdk/internal/ANBannerAdView.m
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ - (NSString *)adType {
return @"inline";
}

- (UIViewController *)displayController {
return self.mraidController ? self.mraidController : self.rootViewController;
}

- (void)adShouldExpandToFrame:(CGRect)frame
closeButton:(UIButton *)closeButton {
[super mraidExpandAd:frame.size
Expand Down
4 changes: 4 additions & 0 deletions sdk/internal/ANInterstitialAd.m
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ - (NSString *)adType {
return @"interstitial";
}

- (UIViewController *)displayController {
return self.mraidController ? self.mraidController : self.controller;
}

- (void)adShouldExpandToFrame:(CGRect)frame
closeButton:(UIButton *)closeButton {
[super mraidExpandAd:frame.size
Expand Down
1 change: 1 addition & 0 deletions sdk/internal/ANMRAIDProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ typedef enum _ANMRAIDState
@property (nonatomic, readwrite, weak) id<ANMRAIDEventReceiver> mraidEventReceiverDelegate;

- (NSString *)adType;
- (UIViewController *)displayController;
- (void)adShouldResetToDefault;
- (void)adShouldExpandToFrame:(CGRect)frame closeButton:(UIButton *)closeButton;
- (void)adShouldResizeToFrame:(CGRect)frame allowOffscreen:(BOOL)allowOffscreen
Expand Down

0 comments on commit 72aa3b0

Please sign in to comment.