Code Monkey home page Code Monkey logo

cjpadcontroller's Introduction

CJPAdController 1.7.1

CJPAdController is a singleton class allowing easy implementation of iAd and Google AdMob ads in your iOS app. It supports all devices and orientations, and works on iOS 6.0+

Features

  • Choose whether to show both iAd and AdMob, or just one of them
  • Choose whether iAd or AdMob is your default ads, falling back to the other if your default is unable to load an ad
  • Choose to display ads at either the top of bottom of your views
  • Specify a time delay for when to start showing ads in a view
  • Automatically hides from view if there are no ads to display
  • Support for hiding ads from users who have purchased a "Remove Ads" In-App Purchase (assumes you store a boolean value for this in NSUserDefaults)

OS/Device Compatibility

  • Works on iOS >= 6.x (use v1.6.3 if you need to support iOS 5.x)
  • Works on all iPhone and iPad screen sizes in both portrait and landscape orientations

Screenshots

CJPAdController screenshot CJPAdController screenshot

CJPAdController screenshot CJPAdController screenshot

Adding to your project

Method 1 - CocoaPods

CocoaPods is the simplest way to get started. Just add pod 'CJPAdController' to your Podfile and run pod install.

Method 2 - Old School

1. Drop the CJPAdController and GoogleMobileAdsSdk folders into your project. NOTE: You may wish to check if there is a newer AdMob SDK available, you'll need at least version 7.0.0.

2. If you're working on a new project you shouldn't need to do anything else. If it's an older project then depending on its settings you may need to manually link all the required frameworks, if so, make sure the following frameworks are linked to your project:

For iAd:

  1. iAd.framework
  2. AdSupport.framework

For AdMob:

  1. AudioToolbox.framework
  2. AVFoundation.framework
  3. CoreGraphics.framework
  4. CoreTelephony.framework
  5. MessageUI.framework
  6. StoreKit.framework
  7. SystemConfiguration.framework
  8. EventKit.framework
  9. EventKitUI.framework

Usage

CJPAdController will automatically display ads at the top or bottom of your view. It is designed to be used with either a UINavigationController or UITabBarController.

1. #import "CJPAdController.h" in your AppDelegate.m.

2. In application didFinishLaunchingWithOptions, configure CJPAdController to your liking using the sharedInstance:

    [CJPAdController sharedInstance].adNetworks = @[@(CJPAdNetworkiAd), @(CJPAdNetworkAdMob)];
    [CJPAdController sharedInstance].adPosition = CJPAdPositionBottom;
    [CJPAdController sharedInstance].initialDelay = 2.0;
    // AdMob specific
    [CJPAdController sharedInstance].adMobUnitID = @"ca-app-pub-1234567890987654/1234567890";

3. Set up your navigation/tabbar controller as usual, then tell CJPAdController to start serving ads in it.

    [[CJPAdController sharedInstance] startWithViewController:_yourNavController];

4. One more thing... you'll need to set the window's rootViewController to the sharedInstance of CJPAdController

    self.window.rootViewController = [CJPAdController sharedInstance];

Configuration Options

Choosing which ad networks are used, and which is preferred

CJPAdController assumes you will be using both iAd and AdMob as that is precisely what this class was written for. By default both will be used and iAd will be the preferred option. You can override this by passing the array in a different order (the first value in the array will be set as your preferred ads), you can even exclude one of the networks if you wish.

[CJPAdController sharedInstance].adNetworks = @[@(CJPAdNetworkAdMob), @(CJPAdNetworkiAd)];

Choosing the position of the ads

By default, ads will slide up from the bottom of the view and be pinned there. Alternatively, you may wish to reverse this and have them slide down and stay at the top of your view.

[CJPAdController sharedInstance].adPosition = CJPAdPositionTop;

Delay the appearance of ads after app has launched

By default, ads will be requested as soon as your app is launched. You can delay this by providing an NSTimeInterval, the following code would wait 2 seconds after your app has launched before requesting an ad:

[CJPAdController sharedInstance].initialDelay = 2.0;

Use within custom view controllers

If you are trying to implement CJPAdController in a custom view controller that isn't a subclass of UINavigationController or UITabBarController, you may see issues causing ads to display incorrectly or not at all. In this case it is possible to override the isNavController property which some users have had success with.

[CJPAdController sharedInstance].overrideIsNavController = YES;

More

There are a number of AdMob specific options that can also be configured, as well as a number of general methods for hiding, removing, restoring ads etc. AdMob ads may also be targeted based on your users' age, gender and location. Please read the comments in the header file before using any of these. You can see an example of these in the demo project, furthermore, the header file is well commented with information on what each method does and how you might want to use them both in testing or in production.

Licence and Attribution

If you're feeling kind you can provide attribution and a link to this GitHub project.

Licence

Copyright (c) 2011-2015 Chris Phillips

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

cjpadcontroller's People

Contributors

chrisjp avatar numen31337 avatar pyrosphere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cjpadcontroller's Issues

Status Bar disappears when playing fullscreen video

I am using CJPAdController below a UITabBarController bar items. This is the configuration code written in Swift:

class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch.

        CJPAdController.sharedInstance().adNetworks = [1]
        CJPAdController.sharedInstance().adPosition = CJPAdPosition.Bottom
        CJPAdController.sharedInstance().initialDelay = 2.0

        let storyBoard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
        let initViewController = storyBoard.instantiateViewControllerWithIdentifier("InitTabBarController") as UIViewController

        CJPAdController.sharedInstance().startWithViewController(initViewController)
        self.window!.rootViewController = CJPAdController.sharedInstance()
        return true
    }

Everything is working fine but when I play a video with AVPlayerViewController in fullscreen and close the controller, the status bar gets hidden. This is the class I am using:

class PlayerViewController: AVPlayerViewController {

    var file:NSString!

    override func viewDidLoad() {
        super.viewDidLoad()

        let videoURL = NSURL(fileURLWithPath: file)
        self.player = AVPlayer.playerWithURL(videoURL) as AVPlayer

        self.player.play()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

 }

I coding for iOS 8.1

AdMob targeting issue

Currently there is no way to set targeting information for AdMob service, i can help you with it if you have any vision how this should be implemented. I think this part of functionality is very important for the such library.

Ad not shown when custom UIViewController is really a UINavigationController

My app is using an instance of SWRevealViewController as the contentController. This is not working because it is not a UINavigationController.

I think this commit broke it for me:
78ae4f7

When _isNavController to YES, it works for me - so for now I have just modified your code.
I think it is impossible for you to recognize how to behave for custom UIViewControllers, but maybe you could add an override property, to force _isNavController or _isTabBar to YES...

Using Different Admob Ad Unit IDs?

Using this library, how can I call specific ad units? For example I have a customized ad to use for a specific view, and another ad for another view controller. How can I let the library display the correct one (this is of course assuming admob is the default choice)?

I also was wondering what the proper way of using this is, when my root view controller isn't embedded within a navigation controller or a tab bar controller. I just have a view controller with multiple segues that lead to other view controllers.

Thank you so much for this by the way!

Exiting a full screen video hides the status bar permanently

Before nothing, thanks for this wonderful tool, it's awesome.
I have configured CJPAdController on my app as the tutorial says and everything seems to be working fine, except when I launch a video, set full screen and then when I click on Done button to exit full screen, the status bar is hidden.

Any suggestion on how to recover the status bar? I tried with [[UIApplication sharedApplication] setStatusBarHidden:NO] on my viewDidDisapear which is triggered when the back button is pressed, but the status bar is not displayed.

Can't install when using use_frameworks

If I try to install alongside a library that is written in Swift (Like SwiftyJSON) I get the following error:

Updating local specs repositories
Analyzing dependencies
Downloading dependencies
Installing CJPAdController (1.7)
Using DateTools (1.6.1)
Installing Google-Mobile-Ads-SDK (7.4.1)
Using SwiftyJSON (2.2.1)
[!] The 'Pods' target has transitive dependencies that include static binaries: (/Users/jengo/Projects/tests/CJPAdControllertest/Pods/Google-Mobile-Ads-SDK/GoogleMobileAdsSdkiOS-7.4.1/GoogleMobileAds.framework)

Installing Google-Mobile-Ads-SDK works fine, but fails when CJPAdController is also listed.

Example Podfile I am using

platform :ios, '8.0'

pod "SwiftyJSON", ">= 2.2"
pod 'CJPAdController'
pod 'DateTools'

use_frameworks!
link_with 'CJPAdControllertest'

...init adController directly in viewcontroller?

Wondering if it's possible to use CJPAdController directly with any chosen viewController instead of initializing from AppDelegate?
Reason is I'm using RESideMenu (github.com/romaonthego/RESideMenu) with storyboards which already is using rootViewController & embedded NavigationController.

Truly like this AdController, so I followed the storyboard instructions and after building app it simply crashes when starting up on device.

Appreciate any help...

Hidding the banner in one screen

Hi! Is there a way to totally remove the banner from one especific ViewController (mine is the last in the stack of a navcontroller)?

Is there a method that should be called inthat ViewController to acomplish this?

Thanks!

Keep Ad Banner on presenting modal view?

Hi wondering is there a workaround to keeping the ad when presenting modal views? I tried using the '-startWithViewController:' method in the modal vc to switch to the new modal view, but that doesn't work. Thanks

Status Bar Style default

Hello,

I'm trying to use CJPAdController but when i add it, the status bar is always set to default and it looks bad on my black navigation bar

I want to set it to light content but i can't. it looks like this overwrites it

self.window.rootViewController = [CJPAdController sharedInstance];

Does anyone had the same problem? how to walk around it? Thanks a lot

Bugsense crash report

Here is the crash report symbolicated form bugsense of my app.
I was using a version of your class downloaded in december 2012, I'm updating my app now with the most recent commit and will let you know if it happens again.

0 libobjc.A.dylib 0x3afec5b6 objc_msgSend + 21
1 Foundation 0x33d01c15 + 24
2 Foundation 0x33d01ccd + 60
3 Foundation 0x33d07653 + 270
4 Foundation 0x33d079db + 386
5 UIKit 0x3559014f + 346
6 UIKit 0x35155c37 + 562
7 UIKit 0x35198e61 + 52
8 My Bet Slip Live 0x000f9c9d 0xf7000 + 11421
9 UIKit 0x351578c9 + 456
10 QuartzCore 0x34f01d8b + 214
11 QuartzCore 0x34f01929 + 460
12 UIKit 0x35157689 + 728
13 My Bet Slip Live 0x000f9d09 0xf7000 + 11529
14 UIKit 0x3516ae99 + 504
15 UIKit 0x3522214f + 58
16 My Bet Slip Live 0x000fa189 0xf7000 + 12681
17 My Bet Slip Live 0x00148f84 0xf7000 + 335748
18 My Bet Slip Live 0x0014d5e4 0xf7000 + 353764
19 My Bet Slip Live 0x0014bcb4 0xf7000 + 347316
20 My Bet Slip Live 0x0015ad38 0xf7000 + 408888
21 My Bet Slip Live 0x00150214 0xf7000 + 365076
22 My Bet Slip Live 0x00148f84 0xf7000 + 335748
23 My Bet Slip Live 0x00140194 0xf7000 + 299412
24 CoreFoundation 0x3334f9c4 + 68
25 CoreFoundation 0x332a6feb + 286
26 CoreFoundation 0x332a6b43 + 50
27 WebKit 0x39bc0653 + 374
28 CoreFoundation 0x3334e61b + 626
29 CoreFoundation 0x332a5f68 _CF_forwarding_prep_0 + 24
30 CoreFoundation 0x3334f9c4 + 68
31 CoreFoundation 0x332a6feb + 286
32 WebCore 0x392ebcf3 + 26
33 WebCore 0x39328d0d + 80
34 CoreFoundation 0x33321683 + 14
35 CoreFoundation 0x33320ee9 + 212
36 CoreFoundation 0x3331fcb7 + 646
37 CoreFoundation 0x33292ebd CFRunLoopRunSpecific + 356
38 CoreFoundation 0x33292d49 CFRunLoopRunInMode + 104
39 GraphicsServices 0x36e562eb GSEventRunModal + 74
40 UIKit 0x351a8301 UIApplicationMain + 1120
41 My Bet Slip Live 0x000fa5e7 0xf7000 + 13799

Problem with Layout in Swift implementation

I am trying to implement in a Swift project.
Currently I have problem with it.

  1. When I try to show ads from bottom, it does not show.
    2)When I Set it to top, it shows but just overlay my current layout.

Do you have any idea?

Support storyboard?

Hello thank for amazing work.

how add ur code with project built in storyboard.

thank you :)

Tabview Controller

I can't get this to work in a tab view. I have CJPAdController in all the view controllers. When the app starts the screen is blank and nothing happens until I click on the second tab. I then go back to first tab view and it will then display with the ad. I'm a newbie so maybe I'm doing something wrong. Great work by the way. I learned a lot by studying the code.

Removed banner still shows up if canceled before initialDelay time passed

Hello,

A case:

  1. Setup CJPAdController with initialDelay of 60 seconds.
  2. Remove the banner before 60 seconds passed.
  3. The banner will still show up, as it's creation is scheduled.

Solution:

Add this one line below code to removeAdsAndMakePermanent:andRemember:, at the beginning of the method:

[NSObject cancelPreviousPerformRequestsWithTarget:self];

Cheers and thanks for a great lib!

Temporarily hiding ads

How could I temporarily hide ads? (in my app I want to implement fullscreen view with no ads on tap)

I only use AdMob, so I could probably do:
[adController removeBanner:@"AdMob" permanently:NO];

but I see no easy way to restore the ad when done?

Status bar and Banner on top

Hello.
Could you please check this line of code

if (!preiOS7 && !_showingiAd && !_showingAdMob && _adPosition==CJPAdPositionTop) {
        contentFrame.origin.y = statusBarHeight;
        contentFrame.size.height -= statusBarHeight;
}

I am using your controller with a simple UIViewController. I try to set

[CJPAdController sharedInstance].overrideIsNavController = YES;

but it was not good. See below:

No visible @interface for 'GADrequest' ...

I got another strange error in one of my projects using CJPAdController.
For some reason I get following error: No visible @interface for 'GADrequest' declares the selector tagForChildDirectedTreatment.

Here is the part of code:

    // COPPA
    if ([_tagForChildDirectedTreatment isEqualToString:@"0"] || [_tagForChildDirectedTreatment isEqualToString:@"1"]) {
        BOOL tagForCOPPA = [_tagForChildDirectedTreatment isEqualToString:@"1"] ? YES : NO;
        [adMobRequest tagForChildDirectedTreatment:tagForCOPPA];
    }

I already checked all settings multiple times, but still can't figure out what happened. The same version of CJPAdController works fine in another project.

iPad iOS 7 wrong device orientation

Hi!

I got a universal app that is working on iPad in landscape mode only. Suddenly, the app shows up in portrait mode, which totally breaks the user experience. Rotating device does not change the orintation. I removed the CJPAdController and it works fine, but I need ads inside.

Please help :(

No resize main viewcontroller

My app has a UIViewController with ads. When load app and show ad, resize the main view of viewcontroller, but when show mail composer and come back, the main view no resize and the bottom buttons no show, why?

Great work!

Status bar being hidden

If the controller tries to present when there is currently a push view controller on the stack, then it fails and hides the status bar in the app.

Compilation error

I am trying to use CJPAdController under Xcode 5.1.1 but I got the following compilation error. I am wondering if it is due to Xcode 5 or not. If not, please help me solving this issue. Thank you.
schermata 2015-02-09 alle 16 57 05

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.