2.在Xcode專案下的General->Linked Frameworks and Libraries增加以下項目
CFNetwork.framework
CoreFoundation.framework
UnityAds.bundle
UnityAds.framework
StoreKit.framework
AdSupport.framework
SystemConfiguration.framework
CoreTelephony.framework
CoreMedia.framework
3.在Xcode專案下的Build Settings->Search Paths->Framework Search Paths
加上UnityAds.Bundle所在的目錄,不然之後會出現UnityAds/UnityAds.h' file not found
4.修改AppController.h
#import <UIKit/UIKit.h>
#import <UnityAds/UnityAds.h>//<---新增這行
@class RootViewController;
//注意下面紅色新增的字符
@interface AppController : NSObject <UIApplicationDelegate,UnityAdsDelegate> {
UIWindow *window;
}
@property(nonatomic, readonly) RootViewController* viewController;
@end
5.修改AppController.mm
先找到下面這幾行:
// Use RootViewController manage CCEAGLView _viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; _viewController.wantsFullScreenLayout = YES; _viewController.view = eaglView;
接著往後加這幾行(注意紅色的數字,替換成自己的廣告Game ID):
//Unity Ads
[[UnityAds sharedInstance] setTestMode:YES];//測試時打開
[[UnityAds sharedInstance] setDebugMode:YES];//測試時打開
[[UnityAds sharedInstance] startWithGameId:@"1234567" andViewController:_viewController];
[[UnityAds sharedInstance] setDelegate:self];
然後在這個檔案找個合適的地方加上這個函式(廣告播完後會到這):
- (void)unityAdsVideoCompleted:(NSString *)rewardItemKey skipped:(BOOL)skipped
{
}
6.增加UnityAdsWrapper.h到專案內(跟AppController.h放同目錄)
class UnityAdsWrapper
{
public:
static bool canShow();
static void show();
};
7.增加UnityAdsWrapper.mm到專案內(跟UnityAdsWrapper.h放同目錄)
#import <Foundation/Foundation.h>
#import <UnityAds/UnityAds.h>
#import "UnityAdsWrapper.h"
bool UnityAdsWrapper::canShow()
{
if ([[UnityAds sharedInstance] canShow] && [[UnityAds sharedInstance] canShowAds]) {
return true;
} else {
return false;
}
}
void UnityAdsWrapper::show()
{
[[UnityAds sharedInstance] show];
}
void UnityAdsWrapper::hide()
{
[[UnityAds sharedInstance] hide];
}
8.然後就可以在模擬器測試了,別忘了加入#include "UnityAdsWrapper.h"
然後用以下程式碼測試:
if(UnityAdsWrapper::canShow()){
UnityAdsWrapper::show();
}
沒有留言:
張貼留言