diff --git a/UnityAds/AdUnit/UADSViewController.m b/UnityAds/AdUnit/UADSViewController.m index f3389dd9..3615c6d2 100644 --- a/UnityAds/AdUnit/UADSViewController.m +++ b/UnityAds/AdUnit/UADSViewController.m @@ -186,25 +186,35 @@ - (void)handleViewPlacement:(UIView *)view { } - (void)createVideoPlayer { - AVURLAsset *asset = nil; - AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset]; - [self setVideoPlayer:[[UADSAVPlayer alloc] initWithPlayerItem:item]]; - [self.videoView setPlayer:self.videoPlayer]; + if (![self videoPlayer]) { + AVURLAsset *asset = nil; + AVPlayerItem *item = [AVPlayerItem playerItemWithAsset:asset]; + [self setVideoPlayer:[[UADSAVPlayer alloc] initWithPlayerItem:item]]; + [self.videoView setPlayer:self.videoPlayer]; + } } - (void)createVideoView { - [self setVideoView:[[UADSVideoView alloc] initWithFrame:[self getRect]]]; - [self.videoView setVideoFillMode:AVLayerVideoGravityResizeAspect]; + if (![self videoView]) { + [self setVideoView:[[UADSVideoView alloc] initWithFrame:[self getRect]]]; + [self.videoView setVideoFillMode:AVLayerVideoGravityResizeAspect]; + } } - (void)destroyVideoView { - [self.videoView removeFromSuperview]; + if ([self videoView]) { + [self.videoView removeFromSuperview]; + } + self.videoView = NULL; } - (void)destroyVideoPlayer { - [self.videoPlayer stop]; - [self.videoPlayer stopObserving]; + if ([self videoPlayer]) { + [self.videoPlayer stop]; + [self.videoPlayer stopObserving]; + } + self.videoPlayer = NULL; } diff --git a/UnityAds/Api/UADSApiCache.m b/UnityAds/Api/UADSApiCache.m index ecf92f0e..39f91303 100644 --- a/UnityAds/Api/UADSApiCache.m +++ b/UnityAds/Api/UADSApiCache.m @@ -104,7 +104,43 @@ + (void)WebViewExposed_getFileContent:(NSString *)fileId encoding:(NSString *)en } } - + (void)WebViewExposed_isCaching:(UADSWebViewCallback *)callback { ++ (void)WebViewExposed_setFileContent:(NSString *)fileId encoding:(NSString *)encoding content:(NSString *)content callback:(UADSWebViewCallback *)callback { + NSString *tagetFilePath = [UADSApiCache fileIdToFilename:fileId]; + NSData *fileContents = nil; + + fileContents = [content dataUsingEncoding:NSUTF8StringEncoding]; + + if (encoding) { + if ([encoding isEqualToString:@"UTF-8"]) { + // UTF-8 handled by default + } + else if ([encoding isEqualToString:@"Base64"]) { + fileContents = [[NSData alloc] initWithBase64EncodedString:content options:0]; + } + else { + [callback error:NSStringFromCacheError(kUnityAdsUnsupportedEncoding) arg1:fileId, tagetFilePath, encoding, nil]; + return; + } + } + + @try { + if (![[NSFileManager defaultManager] fileExistsAtPath:tagetFilePath]) { + [[NSFileManager defaultManager] createFileAtPath:tagetFilePath contents:nil attributes:nil]; + } + if (![[NSFileManager defaultManager] isWritableFileAtPath:tagetFilePath]) { + [callback error:NSStringFromCacheError(kUnityAdsFileIOError) arg1:fileId, tagetFilePath, encoding, nil]; + return; + } + [fileContents writeToFile:tagetFilePath atomically:YES]; + } + @catch (NSException *exception) { + [callback error:NSStringFromCacheError(kUnityAdsFileIOError) arg1:fileId, tagetFilePath, exception.reason, nil]; + return; + } + [callback invoke:nil]; +} + ++ (void)WebViewExposed_isCaching:(UADSWebViewCallback *)callback { [callback invoke:[NSNumber numberWithBool:[UADSCacheQueue hasOperations]], nil]; } diff --git a/UnityAds/Configuration/UADSInitialize.m b/UnityAds/Configuration/UADSInitialize.m index e8b0be65..58c9de12 100644 --- a/UnityAds/Configuration/UADSInitialize.m +++ b/UnityAds/Configuration/UADSInitialize.m @@ -171,9 +171,8 @@ - (instancetype)execute { NSString *localWebViewFile = [UADSSdkProperties getLocalWebViewFile]; if ([[NSFileManager defaultManager] fileExistsAtPath:localWebViewFile]) { - NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:localWebViewFile]; - NSData *fileData = [fileHandle readDataToEndOfFile]; - NSString *fileString = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding]; + NSData *fileData = [NSData dataWithContentsOfFile:localWebViewFile options:NSDataReadingUncached error:nil]; + NSString *fileString = [[NSString alloc] initWithBytesNoCopy:(void *)[fileData bytes] length:[fileData length] encoding:NSUTF8StringEncoding freeWhenDone:NO]; NSString *localWebViewHash = [fileString sha256]; if (!localWebViewHash || (localWebViewHash && [localWebViewHash isEqualToString:self.configuration.webViewHash])) { diff --git a/UnityAds/MetaData/UADSMediationMetaData.h b/UnityAds/MetaData/UADSMediationMetaData.h index 5f49a285..fefede88 100644 --- a/UnityAds/MetaData/UADSMediationMetaData.h +++ b/UnityAds/MetaData/UADSMediationMetaData.h @@ -5,5 +5,6 @@ - (void)setName:(NSString *)mediationNetworkName; - (void)setVersion:(NSString *)mediationSdkVersion; - (void)setOrdinal:(int)mediationOrdinal; +- (void)setMissedImpressionOrdinal:(int)missedImpressionOrdinal; -@end \ No newline at end of file +@end diff --git a/UnityAds/MetaData/UADSMediationMetaData.m b/UnityAds/MetaData/UADSMediationMetaData.m index 1b473042..1cc3ce95 100644 --- a/UnityAds/MetaData/UADSMediationMetaData.m +++ b/UnityAds/MetaData/UADSMediationMetaData.m @@ -19,4 +19,8 @@ - (void)setOrdinal:(int)mediationOrdinal { [self set:@"ordinal" value:[NSNumber numberWithInt:mediationOrdinal]]; } -@end \ No newline at end of file +- (void)setMissedImpressionOrdinal:(int)missedImpressionOrdinal { + [self set:@"missedImpressionOrdinal" value:[NSNumber numberWithInt:missedImpressionOrdinal]]; +} + +@end diff --git a/UnityAds/Properties/UADSClientProperties.m b/UnityAds/Properties/UADSClientProperties.m index 30ef35d7..9b4ed57c 100644 --- a/UnityAds/Properties/UADSClientProperties.m +++ b/UnityAds/Properties/UADSClientProperties.m @@ -16,7 +16,11 @@ + (NSString *)getGameId { } + (NSArray*)getSupportedOrientationsPlist { - return [NSBundle.mainBundle.infoDictionary objectForKey:@"UISupportedInterfaceOrientations"]; + NSArray *supportedOrientations = @[]; + if ([NSBundle.mainBundle.infoDictionary objectForKey:@"UISupportedInterfaceOrientations"] != nil) { + supportedOrientations = [supportedOrientations arrayByAddingObjectsFromArray:[NSBundle.mainBundle.infoDictionary objectForKey:@"UISupportedInterfaceOrientations"]]; + } + return supportedOrientations; } + (int)getSupportedOrientations { @@ -32,16 +36,7 @@ + (NSString *)getAppVersion { } + (BOOL)isAppDebuggable { - static BOOL output = NO; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - // Check simulator, TestFlight builds and not AppStore apps which should have mobileprovision file - if (UADSDevice.isSimulator || - [NSBundle.mainBundle.appStoreReceiptURL.lastPathComponent isEqualToString:@"sandboxReceipt"] || - [NSData dataWithContentsOfFile:[NSBundle.mainBundle pathForResource:@"embedded" ofType:@"mobileprovision"]]) - output = YES; - }); - return output; + return NO; } + (void)setCurrentViewController:(UIViewController *)viewController { diff --git a/UnityAds/Properties/UADSSdkProperties.m b/UnityAds/Properties/UADSSdkProperties.m index 47cb39df..9248be25 100644 --- a/UnityAds/Properties/UADSSdkProperties.m +++ b/UnityAds/Properties/UADSSdkProperties.m @@ -4,10 +4,10 @@ NSString * const kUnityAdsLocalCacheFilePrefix = @"UnityAdsCache-"; NSString * const kUnityAdsLocalStorageFilePrefix = @"UnityAdsStorage-"; NSString * const kUnityAdsWebviewBranchInfoDictionaryKey = @"UADSWebviewBranch"; -NSString * const kUnityAdsVersionName = @"2.1.1"; +NSString * const kUnityAdsVersionName = @"2.1.2"; NSString * const kUnityAdsFlavorDebug = @"debug"; NSString * const kUnityAdsFlavorRelease = @"release"; -int const kUnityAdsVersionCode = 2101; +int const kUnityAdsVersionCode = 2102; @implementation UADSSdkProperties diff --git a/UnityAdsExample/ViewController.m b/UnityAdsExample/ViewController.m index 39a86a08..30243bc5 100644 --- a/UnityAdsExample/ViewController.m +++ b/UnityAdsExample/ViewController.m @@ -55,7 +55,7 @@ - (IBAction)toggleTestMode:(id)sender { } - (IBAction)incentivizedButtonTapped:(id)sender { - if ([UnityAds isReady]) { + if ([UnityAds isReady:self.incentivizedPlacementId]) { self.incentivizedButton.enabled = NO; UADSPlayerMetaData *playerMetaData = [[UADSPlayerMetaData alloc] init]; [playerMetaData setServerId:@"rikshot"]; @@ -70,7 +70,7 @@ - (IBAction)incentivizedButtonTapped:(id)sender { } - (IBAction)interstitialButtonTapped:(id)sender { - if ([UnityAds isReady]) { + if ([UnityAds isReady:self.interstitialPlacementId]) { self.interstitialButton.enabled = NO; UADSPlayerMetaData *playerMetaData = [[UADSPlayerMetaData alloc] init]; [playerMetaData setServerId:@"rikshot"]; diff --git a/UnityAdsTests/ClientPropertiesTest.m b/UnityAdsTests/ClientPropertiesTest.m index f0d3eb07..d5e1a8ab 100644 --- a/UnityAdsTests/ClientPropertiesTest.m +++ b/UnityAdsTests/ClientPropertiesTest.m @@ -43,7 +43,7 @@ - (void)testSetDelegate { } - (void)testIsAppDebuggable { - XCTAssertTrue([UADSClientProperties isAppDebuggable], "App should be debuggable"); + XCTAssertFalse([UADSClientProperties isAppDebuggable], "App should not be debuggable"); } - (void)testSetGameId {