屏幕在启动xcode模拟器上变黑

时间:2013-08-08 12:46:58

标签: iphone ios objective-c

我在没有解决问题的情况下对我的问题做了一些研究。我的项目成功编译并启动,但模拟器只显示黑色。在我将googles插页式广告添加到我的应用之前,我的项目工作正常。以下是我实现此目的的代码:

Appdelegate.h

@interface AppDelegate : UIResponder <UIApplicationDelegate,GADInterstitialDelegate> {

    UIWindow *window_;
    MainViewController *mainController;
    GADInterstitial *splashInterstitial_;
}

@property (nonatomic, retain) UIWindow *window;
@property(nonatomic, retain) IBOutlet MainViewController *mainController;
@property(nonatomic, readonly) NSString *interstitialAdUnitID;

- (GADRequest *)createRequest;

Appdelegate.m

#define INTERSTITIAL_AD_UNIT_ID @""

@synthesize mainController = mainViewController_;
@synthesize window = window_;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

[self.window setRootViewController:mainViewController_];
    [self.window makeKeyAndVisible];

    splashInterstitial_ = [[GADInterstitial alloc] init];

    splashInterstitial_.adUnitID = self.interstitialAdUnitID;
    splashInterstitial_.delegate = self;

    [splashInterstitial_ loadAndDisplayRequest:[self createRequest]
                                   usingWindow:self.window
                                  initialImage:[UIImage imageNamed:@"InitialImage"]];
}

- (void)dealloc {
    splashInterstitial_.delegate = nil;
}

- (NSString *)interstitialAdUnitID {
    return INTERSTITIAL_AD_UNIT_ID;
}


#pragma mark GADRequest generation


- (GADRequest *)createRequest {
    GADRequest *request = [GADRequest request];


    request.testDevices =
    [NSArray arrayWithObjects:

     nil];
    return request;

}

MainViewController.h

@interface MainViewController : UIViewController <GADInterstitialDelegate> {
    UIButton *interstitialButton_;
    GADInterstitial *interstitial_;
}

@property (nonatomic, retain) GADInterstitial *interstitial;
@property (nonatomic, retain) IBOutlet UIButton *interstitialButton;

- (IBAction)showInterstitial:(id)sender;

MainViewController.m

@synthesize interstitialButton = interstitialButton_;
@synthesize interstitial = interstitial_;


- (void)interstitial:(GADInterstitial *)interstitial
didFailToReceiveAdWithError:(GADRequestError *)error {
    // Alert the error.
    UIAlertView *alert = [[UIAlertView alloc]
                           initWithTitle:@"GADRequestError"
                           message:[error localizedDescription]
                           delegate:nil cancelButtonTitle:@"Drat"
                           otherButtonTitles:nil] ;
    [alert show];

    interstitialButton_.enabled = YES;
}

- (void)interstitialDidReceiveAd:(GADInterstitial *)interstitial {
    [interstitial presentFromRootViewController:self];
    interstitialButton_.enabled = YES;
}

- (IBAction)showInterstitial:(id)sender {

    self.interstitial = [[GADInterstitial alloc] init] ;
    self.interstitial.delegate = self;


    AppDelegate *appDelegate =
    (AppDelegate *)
    [UIApplication sharedApplication].delegate;
    self.interstitial.adUnitID = appDelegate.interstitialAdUnitID;

    [self.interstitial loadRequest: [appDelegate createRequest]];
    interstitialButton_.enabled = NO;
}

0 个答案:

没有答案