cocoa-touch - 如何在我的 iPhone 应用程序中创建自定义广告?

标签 cocoa-touch iad ads

我正在为我的大学广播电台开发一个 iPhone 应用程序,我想插入广告(外观和感觉就像 iAds)但有我自己的自定义设计/内容/链接,这样我就可以把这个广告空间卖给可能的赞助商.
有谁知道我该怎么做或指出正确的方向吗?我正在构建一个“实用程序”风格的应用程序。

最佳答案

我的服务器上有一个 JSON 文件,其中包含有关广告的某些数据(我的服务器恰好设置了一个,但您可以以相同的方式容纳多个)。

{"promo":"yes","imageURL":"http://somedomain/testAd.png","image2xURL":"http://somedomain/testAd@2x.png","link":"http://www.whereTheAdShouldDirect.com"}

然后,在应用程序中,我在 viewWillAppear 的其余部分中有这个:

NSURL *url = [NSURL URLWithString:@"http://www.mydomain/promo.php"];

NSString *response = [[NSString alloc] initWithContentsOfURL:url];
const char *convert = [response UTF8String];
NSString *responseString = [NSString stringWithUTF8String:convert];
NSDictionary *promo = [responseString JSONValue];

[response release];
if([[promo objectForKey:@"promo"] isEqualToString:@"yes"]){
    self.linkURL = [NSURL URLWithString:[promo objectForKey:@"link"]];
    NSURL *picURL = [NSURL URLWithString:[promo objectForKey:@"imageURL"]];
    if([[[UIDevice currentDevice] systemVersion]intValue]>=4){
        if([[UIScreen mainScreen] scale]==2.0){
            picURL = [NSURL URLWithString:[promo objectForKey:@"image2xURL"]];
        }
    }
    CGRect imgFrame = CGRectMake(0, 0, 320, 50);
    UIButton *adImage=[[UIButton alloc] initWithFrame:imgFrame];
    NSData * imageData = [NSData dataWithContentsOfURL:picURL];
    UIImage * image = [UIImage imageWithData:imageData];
    [adImage setBackgroundImage:image forState:UIControlStateNormal];
    [adImage addTarget:self action:@selector(ad) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:adImage];
    [adImage release];
}

还有这个方法:

-(void)ad{
    [[UIApplication sharedApplication] openURL:self.linkURL];
}

您可能希望根据您希望广告使用react的方式更改最后一种方法(直接在应用中加载 WebView ?)

关于cocoa-touch - 如何在我的 iPhone 应用程序中创建自定义广告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8685710/

相关文章:

ruby-on-rails - Ruby on Rails 的广告/横幅管理/轮播?

ios5 - iAd 无法在 iOS 6 上运行

ios - 如何正确隐藏这些广告横幅?

iphone - 有没有办法在 Objective-C 中程序运行时不断调用方法?

iphone - dealloc,使用 release 或设置为 nil 属性?

iphone - 将 iAD 集成到 3d 游戏中

java - AdMob Android 集成 - 需要什么权限?

javascript - 用脚本标记的 jQuery 附加替换 document.write

iphone - 如何获取UISlider拇指图像的中心

ios - 应该相等的字符串比较不相等