'추가'에 해당되는 글 2건

  1. 2012.01.26 cocos2D 에서 iAd 및 AdMob 기능 추가 하는법
  2. 2011.04.09 개발자 프로파일을 추가
아이폰어플개발정보2012. 1. 26. 11:03
http://www.cocos2d-iphone.org/forum/topic/8424
애드몹을 사용 하시기 위해서는 위의 사이트에서 등록 하여 고유 넘버 키를 받으셔야 사용이가능 합니다.
참고 사이트 입니다.


=============================================================================
AdViewController.h
#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
#import "AdMobDelegateProtocol.h"

@protocol AdViewControllerDelegate;

@interface AdViewController : UIViewController <ADBannerViewDelegate, AdMobDelegate>
{
 id <AdViewControllerDelegate> delegate;
 id adBannerView;

 AdMobView* adMobAd;
}

@property (nonatomic, assign) id <AdViewControllerDelegate> delegate;

- (id)initWithMasterView:(UIView*)masterView;
- (void)rotateBannerView:(UIDeviceOrientation)toDeviceOrientation;

@end

@protocol AdViewControllerDelegate

- (void)adController:(AdViewController*)controller didLoadiAd:(id)iadBanner;
- (void)adController:(AdViewController*)controller didFailedToRecieveiAd:(id)iadBanner;

- (void)adController:(AdViewController*)controller didLoadAdMobAd:(AdMobView*)adMobBanner;
- (void)adController:(AdViewController*)controller didFailedToRecieveAdMobAd:(AdMobView*)adMobBanner;

@end

AdViewController.m

#import "AdViewController.h"
#import "cocos2d.h"

#import "AdMobView.h"

@implementation AdViewController

@synthesize delegate;

- (UIDeviceOrientation)currentOrientation
{
 return [[CCDirector sharedDirector] deviceOrientation];
}

- (id) initWithMasterView:(UIView*) masterView
{
 if( nil != (self = [super init]) )
 {
  [self setView:masterView];

  //Initialize the class manually to make it compatible with iOS < 4.0
  Class classAdBannerView = NSClassFromString(@"ADBannerView");
  if (classAdBannerView != nil)
  {
   adBannerView = [[classAdBannerView alloc] initWithFrame:CGRectZero];
   [adBannerView setDelegate:self];
   [adBannerView setRequiredContentSizeIdentifiers: [NSSet setWithObjects:
                 ADBannerContentSizeIdentifier320x50,
                 ADBannerContentSizeIdentifier480x32, nil]];

   [self.view addSubview:adBannerView];

   [self rotateBannerView:[self currentOrientation]];

   [adBannerView setHidden:YES];

  }
  else
  {
   //Request an AdMob Ad
   adMobAd = [AdMobView requestAdOfSize:ADMOB_SIZE_320x48 withDelegate:self];
   [adMobAd retain];
  }
 }

 return self;
}

- (void)rotateBannerView:(UIDeviceOrientation)toDeviceOrientation
{
 if (adBannerView)
 {
  if (UIDeviceOrientationIsLandscape(toDeviceOrientation))
   [adBannerView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifier480x32];
  else
   [adBannerView setCurrentContentSizeIdentifier:ADBannerContentSizeIdentifier320x50];

  [(UIView*)adBannerView setTransform:CGAffineTransformIdentity];

  //Set the transformation for each orientation
  switch (toDeviceOrientation)
  {
   case UIDeviceOrientationPortrait:
   {
    [(UIView*)adBannerView setCenter:CGPointMake(160, 455)];
   }
    break;
   case UIDeviceOrientationPortraitUpsideDown:
   {
    [(UIView*)adBannerView setTransform:CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(180))];
    [adBannerView setCenter:CGPointMake(160, 25)];
   }
    break;
   case UIDeviceOrientationLandscapeLeft:
   {
    [(UIView*)adBannerView setTransform:CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(90))];
    [adBannerView setCenter:CGPointMake(16, 240)];
   }
    break;
   case UIDeviceOrientationLandscapeRight:
   {
    [(UIView*)adBannerView setTransform:CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(-90))];
    [adBannerView setCenter:CGPointMake(304, 240)];
   }
    break;
   default:
    break;
  }
 }

 if (adMobAd)
 {
  [adMobAd setTransform:CGAffineTransformIdentity];

  //Set the transformation for each orientation
  switch (toDeviceOrientation)
  {
   case UIDeviceOrientationPortrait:
   {
    [adMobAd setCenter:CGPointMake(160, 456)];
   }
    break;
   case UIDeviceOrientationPortraitUpsideDown:
   {
    [adMobAd setTransform:CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(180))];
    [adMobAd setCenter:CGPointMake(160, 24)];
   }
    break;
   case UIDeviceOrientationLandscapeLeft:
   {
    [adMobAd setTransform:CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(90))];
    [adMobAd setCenter:CGPointMake(24, 240)];
   }
    break;
   case UIDeviceOrientationLandscapeRight:
   {
    [adMobAd setTransform:CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(-90))];
    [adMobAd setCenter:CGPointMake(296, 240)];
   }
    break;
   default:
    break;
  }
 }
}

#pragma mark -
#pragma mark ADBannerViewDelegate

- (BOOL)allowActionToRun
{
 return YES;
}

- (void) stopActionsForAd
{
 //Pause background music here

 [adBannerView setHidden:YES];

 [[CCDirector sharedDirector] stopAnimation];
 [[CCDirector sharedDirector] pause];
}

- (void) startActionsForAd
{
 //Resume background music here

 [self rotateBannerView:[self currentOrientation]];
 [[UIApplication sharedApplication] setStatusBarOrientation:(UIInterfaceOrientation)[self currentOrientation]];
 [adBannerView setHidden:NO];

 [[CCDirector sharedDirector] stopAnimation];
 [[CCDirector sharedDirector] resume];
 [[CCDirector sharedDirector] startAnimation];
}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
 BOOL shouldExecuteAction = [self allowActionToRun];
    if (!willLeave && shouldExecuteAction)
    {
  [self stopActionsForAd];
    }
    return shouldExecuteAction;
}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
 [adBannerView setHidden:NO];
 [delegate adController:self didLoadiAd:banner];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
 [adBannerView setHidden:YES];
 [delegate adController:self didFailedToRecieveiAd:banner];
}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
 [self startActionsForAd];
}

#pragma mark -
#pragma mark AdMobDelegate methods

- (NSString *)publisherIdForAd:(AdMobView *)adView
{
 return @"your_admob_publisher_id";    //replace it with you publisher id
}

- (UIViewController *)currentViewControllerForAd:(AdMobView *)adView {
 return self;
}

- (UIColor *)adBackgroundColorForAd:(AdMobView *)adView
{
 return [UIColor colorWithRed:0 green:0 blue:0 alpha:1]; // this should be prefilled; if not, provide a UIColor
}

- (UIColor *)primaryTextColorForAd:(AdMobView *)adView
{
 return [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; // this should be prefilled; if not, provide a UIColor
}

- (UIColor *)secondaryTextColorForAd:(AdMobView *)adView
{
 return [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; // this should be prefilled; if not, provide a UIColor
}

- (NSArray *)testDevices
{
 return [NSArray arrayWithObjects: ADMOB_SIMULATOR_ID, nil];
}

- (void)didReceiveAd:(AdMobView *)adView
{
 CCLOG(@"AdMob: Did receive ad");

 [self rotateBannerView:[self currentOrientation]];
 [self.view addSubview:adMobAd];

 [delegate adController:self didLoadAdMobAd:adView];
}

// Sent when an ad request failed to load an ad
- (void)didFailToReceiveAd:(AdMobView *)adView
{
 CCLOG(@"AdMob: Did fail to receive ad");
 [adMobAd removeFromSuperview];
 [adMobAd release];
 adMobAd = nil;

 [delegate adController:self didFailedToRecieveAdMobAd:adView];
}

#pragma mark -
#pragma mark Memory Management

- (void) dealloc
{
 if (adMobAd)
 {
  [adMobAd setDelegate:nil];
  [adMobAd removeFromSuperview];
  [adMobAd release];
  adMobAd = nil;
 }

 if (adBannerView)
 {
  [adBannerView setDelegate:nil];
  [adBannerView removeFromSuperview];
  [adBannerView release];
  adBannerView = nil;
 }

    [super dealloc];
}

@end

The usage is very simple, #importAdViewController.h in you Layer's .h and add the delegate protocol AdViewControllerDelegate

#import "AdViewController.h"

@interface Menu : CCLayer <AdViewControllerDelegate>
{
 AdViewController *adController;
}

And in your layer's .m add this

- (void)onEnter
{
 [super onEnter];

 adController = [[AdViewController alloc] initWithMasterView:[[CCDirector sharedDirector] openGLView]];
 [adController setDelegate:self];

}

- (void)onExit
{
 //Completely remove the controller
 [adController setDelegate:nil];
 [adController release];
 adController = nil;

 [super onExit];
}

- (void)adController:(AdViewController*)controller didLoadiAd:(id)iadBanner;
{
 //Do something when the ad loads, like moving objects.
}

- (void)adController:(AdViewController*)controller didFailedToRecieveiAd:(id)iadBanner;
{
 //Do something when the ad fails to load, like moving objects.;
}

- (void)adController:(AdViewController*)controller didLoadAdMobAd:(AdMobView*)adMobBanner;
{
 //Do something when the ad loads, like moving objects.
}

- (void)adController:(AdViewController*)controller didFailedToRecieveAdMobAd:(AdMobView*)adMobBanner;
{
 //Do something when the ad fails to load, like moving objects.
}
<script src="http://gods2000.tistory.com/plugin/CallBack_bootstrapper?&src=https://s1.daumcdn.net/cfs.tistory/v/0/blog/plugins/CallBack/callback&id=29&callbackId=gods2000tistorycom292340&destDocId=callbacknestgods2000tistorycom292340&host=http://gods2000.tistory.com&float=left&random=631"></script> 출처 :http://gods2000.tistory.com/29
Posted by 오늘마감

댓글을 달아 주세요

이번에는 Xcode에 개발자 프로파일을 추가한다.

Xcode는 애플의 개발환경이며, Apple Iphone SDK를 설치하면 자동으로 함께 설치된다.
실행하기 위해서는 데스크탑(바탕화면)의 자신의 하드디스크 (예: Macintosh HD)에 Developer > Applications 디렉토리에 위치한 Xcode를 실행시키면 된다.
 
1. Xcode를 실행한다.

2. 처음 실행하면 위와 같은 화면이 뜨는데, 여기서 보지 말고 메뉴의 Window > Organizer 를 실행시킨다.

 

3. 개발용으로 사용할 아이팟터치(아이폰)을 연결시킨다. 
연결시키면 다음과 같이 인식을 하게 되는데, "Use for Development"를 클릭하면 "Organizer"에 개발용 기기로 등록된다.

4. 다음과 같이 등록되었으면, "Identifider"에 씌여있는 40자리 문자를 복사한다.

5. 다시 "Program Portal"로 돌아가서 좌측 메뉴의 "Devices"를 선택하고, 상단의 "Add Device"를 클릭하여 자신의 기기를 등록한다.

6. "Device Name"은 원하는대로 적고, "Device ID"는 방금 복사했던 "Identifier" 값을 붙여넣기 한다.
그리고 "+"를 눌러 추가하고 "Submit"버튼을 클릭하면 기기가 등록된다.

7. 좌측 메뉴의 "App IDs"를 클릭하고, 오른쪽의 "Add ID"를 클릭하여 ID를 등록한다.

google_protectAndRun("ads_core.google_render_ad", google_handleError, google_render_ad);

8. "Apple ID Name"과 "App ID"를 등록한다. 개발자용이므로 아무거나 적어도 된다. 역시나 "+"와 "Submit"버튼을 클릭하여 추가한다.

9. 좌측 메뉴의 "Provisioning"으로 가서 "Add Profile"을 클릭하여 프로파일을 생성한다. (Development탭에서 진행한다.)

10. "Profile Name"을 자신이 원하는대로 적고 "Cetificates", "App ID", "Devices"를 자신이 등록했던 대로 선택하고, "Submit"버튼을 눌러 프로파일을 생성한다.

11. "Action"에 "Download"버튼을 클릭하여 프로파일 파일을 다운로드 받는다. "Download"버튼이 생기기 까지 시간이 좀 걸릴 수 있으므로 "Download"버튼이 없으면, 새로고침을 한다.

12. "Xcode"의 "Organizer"로 돌아와서, 방금 다운로드 받은 프로파일 파일을 "PROVISIONING PROFILES"에 끌어다 놓는다. 그럼 아래처럼 프로파일이 등록될 것이다.

이로써 기기연결을 위한 모든 준비를 마쳤다. 



출처 : http://blog.naver.com/PostView.nhn?blogId=co0coa&logNo=130087635018
Posted by 오늘마감

댓글을 달아 주세요