Besides, adding the iAd and AdMob code to get banner to appear on screen, is the following code the correct way to set up a shared banner?
In AppDelegate.h
#import GoogleMobileAds;
#import <UIKit/UIKit.h>
#import <iAd/iAd.h>
#import <GoogleMobileAds/GoogleMobileAds.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property(nonatomic, strong) ADBannerView *iAdView;
#property(nonatomic, strong) GADBannerView *adMobView;
#end
AppDelegate.m
#import "AppDelegate.h"
#import <iAd/iAd.h>
#implementation AppDelegate
#synthesize iAdView;
#synthesize adMobView;
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
iAdView= [[ADBannerView alloc]init];
return YES;
}
iPhone6.m
#import "iPhone6.h"
#import <iAd/iAd.h>
#import "AppDelegate.h"
-(AppDelegate *) appdelegate {
return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}
-(void)viewDidLoad{
iAdView =[[self appdelegate] iAdView];
}
Related
I have a problem obtaining the value of a NSString, named latitudeString from another class. Currently I have two view controllers, the first has users coordinates and the second has a MKMapView which show the current user position on a map. The problem is that I want the pin to show the coordinates of the user position in his subtitle but I can't obtain the value of latitudeString and Xcode gives me this error:
Property 'latitudeString' not found on object of type 'ViewController *'
Here's the code:
ViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#interface ViewController : UIViewController <CLLocationManagerDelegate>
{
}
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
{
CLLocation *newLocation;
NSString *latitudeString;
}
#property (strong, nonatomic) CLLocationManager *locationManager;
#property (strong, nonatomic) NSString *latitudeString;
#end
#implementation ViewController
#synthesize latitudeString;
CLLocationManager *locationManager;
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
newLocation = [locations lastObject];
latitudeString = [NSString stringWithFormat:#"%g\u00B0", newLocation.coordinate.latitude];
}
#end
MapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#interface MapViewController : UIViewController <MKMapViewDelegate>
{
}
#end
MapViewController.m
#import "MapViewController.h"
#import "ViewController.h"
#interface MapViewController ()
{
ViewController *firstViewController;
}
#property (strong, nonatomic) ViewController *firstViewController;
#property (strong, nonatomic) IBOutlet MKMapView *mapView;
#end
#implementation MapViewController
#synthesize firstViewController;
- (void)viewDidLoad
{
self.mapView.showsUserLocation = YES;
self.mapView.delegate = self;
self.mapView.userLocation.title = #"Posizione attuale";
self.mapView.userLocation.subtitle = [NSString stringWithFormat:#"%#", firstViewController.latitudeString]; // ERROR
[super viewDidLoad];
}
#end
Can someone help me with this problem? Thanks.
Update #1
ViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#interface ViewController : UIViewController <CLLocationManagerDelegate>
{
CLLocation *newLocation;
NSString *latitudeString;
}
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
{
}
#property (strong, nonatomic) CLLocationManager *locationManager;
#end
#implementation ViewController
CLLocationManager *locationManager;
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
newLocation = [locations lastObject];
self->latitudeString = [NSString stringWithFormat:#"%g\u00B0", newLocation.coordinate.latitude];
}
#end
MapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#interface MapViewController : UIViewController <MKMapViewDelegate>
{
ViewController *firstViewController;
}
#property (strong, nonatomic) ViewController *firstViewController;
#property (strong, nonatomic) IBOutlet MKMapView *mapView;
#end
MapViewController.m
#import "MapViewController.h"
#import "ViewController.h"
#interface MapViewController ()
{
}
#end
#implementation MapViewController
- (void)viewDidLoad
{
self.mapView.showsUserLocation = YES;
self.mapView.delegate = self;
self.mapView.userLocation.title = #"Posizione attuale";
self.mapView.userLocation.subtitle = [NSString stringWithFormat:#"%#", firstViewController->latitudeString]; // ERROR
[super viewDidLoad];
}
#end
The latitudeString property of ViewController is a private property. Only methods of ViewController can access it. If you want it to be a public property you need to move the property declaration to the .h file.
BTW - get rid of all of your calls to #synthesize. As used, they are obsolete. Also get rid of the ivars you defined for the properties. They are also obsolete.
Try this:
ViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
#interface ViewController : UIViewController <CLLocationManagerDelegate>
// A public property
#property (strong, nonatomic) NSString *latitudeString;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
// A private property
#property (strong, nonatomic) CLLocationManager *locationManager;
#end
#implementation ViewController {
// A private instance variable (ivar)
CLLocation *newLocation;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
newLocation = [locations lastObject];
self.latitudeString = [NSString stringWithFormat:#"%g\u00B0", newLocation.coordinate.latitude];
}
#end
Since I switched my iOS project to ARC, I keep getting this compiler error:
No visible #interface for 'CDViewController' declares the selector
'setUseAgof:'
In this line:
[self.viewController setUseAgof:false];
In this file:
AppDelegate.m
#import "AppDelegate.h"
#import "MainViewController.h"
#import <Cordova/CDVPlugin.h>
#import "NSString+MD5.h"
#implementation AppDelegate
#synthesize window, viewController;
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
// (...)
[self.viewController setUseAgof:false]; // <-- HERE
// (...)
return YES;
}
#end
Although the method is definitely defined:
MainViewController.h
#import <Cordova/CDVViewController.h>
#import <ADTECHMobileSDK/ADTECHMobileSDK.h>
#interface MainViewController : CDVViewController <ATInterstitialViewDelegate>{
ATInterstitialView *interstitial;
}
- (void)setUseAgof:(BOOL)useAgofParam;
#end
#interface MainCommandDelegate : CDVCommandDelegateImpl
#end
#interface MainCommandQueue : CDVCommandQueue
#end
MainViewController.m
#import "MainViewController.h"
#interface MainViewController()
- (void)setUseAgof:(BOOL)useAgofParam;
#end
#implementation MainViewController
BOOL useAgof = true;
- (void)setUseAgof:(BOOL)useAgofParam
{
NSLog(#"1.) Setting useAgof = %d", (int)useAgofParam);
useAgof = useAgofParam;
}
I don't get it. What's wrong?
Update:
AppDelegate.h
#import <UIKit/UIKit.h>
#import <Cordova/CDVViewController.h>
#import <INFOnlineLibrary/INFOnlineLibrary.h>
#interface AppDelegate : NSObject <UIApplicationDelegate>{}
#property (nonatomic, strong) IBOutlet UIWindow* window;
#property (nonatomic, strong) IBOutlet CDVViewController* viewController;
#end
viewController seems to be declared as pointer of CDVViewController. You are calling a method which is part of MainViewController the class derived from CDVViewController. Method being called is part of derived class and not the base class, hence make viewController pointer of MainViewController instead.
Make sure the viewController property in your AppDelegate has a type of CDVViewController * rather than UIViewController *.
I'm trying to add StackMob to my project. It says to create an SMClient instance after having dragged the SDK to the project, checking 'create groups for..' and adding to target. I followed these steps.
However, when I'm creating my SMClient and SMCoreDataStore instances, it gives me an error of Receiver 'SMClient' for class message is a forward declaration and the same for SMCoreDataStore. Here's my code:
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#class SMClient;
#class SMCoreDataStore;
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) NSManagedObjectModel *managedObjectModel;
#property (strong, nonatomic) SMCoreDataStore *coreDataStore;
#property (strong, nonatomic) SMClient *client;
#end
And part of my .m:
#import "AppDelegate.h"
#import "StackMob.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.client = [[SMClient alloc] initWithAPIVersion:#"0" publicKey:#"YOUR_PUBLIC_KEY"];
self.coreDataStore = [self.client coreDataStoreWithManagedObjectModel:self.managedObjectModel];
return YES;
}
I already cleaned the project, imported the relevant header files, but it still gives that error.
Any ideas?
This might be happening because you forgot to import the classes.
Add it on your .m:
#import "SMClient.h"
#import "SMCoreDataStore.h"
I tried to make Renren iOS app along with SocialPlugin docs.
http://wiki.mobile.renren.com/en/index.php/Social_Plugin_Download
I made AppDelegate belows. But every time I invoke app, it failed
at the point of RMConnectCenter initializeConnectWithAPIKey.
The Code is like this.
--noriakiAppDelegate.h--
#import <UIKit/UIKit.h>
#import "RMConnectCenter.h"
#class noriakiViewController;
#interface noriakiAppDelegate : UIResponder <UIApplicationDelegate,RenrenMobileDelegate>
#property (strong, nonatomic) UIWindow *window;
#property (strong, nonatomic) noriakiViewController *noriakiviewcontroller;
#end
--noriakiAppDelegate.h.m--
#import "noriakiAppDelegate.h"
#import "noriakiViewController.h"
#implementation noriakiAppDelegate
#synthesize window = _window;
#synthesize noriakiviewcontroller = _noriakiviewcontroller;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[RMConnectCenter initializeConnectWithAPIKey:#"MY API KEY" secretKey:#"MY SECRET" appId:#"2080970" mobileDelegate:self];
return YES;
}
You mean application crashes when you call initializeConnectWithAPIKey ?
You are not passing your API Key and secret
[RMConnectCenter initializeConnectWithAPIKey:#"MY API KEY" secretKey:#"MY SECRET" appId:#"2080970" mobileDelegate:self];
Are you using storyboards?
i try a simple Delegate but the method won't fire. Here is my code:
The view with the protocol and a button which should trigger the delegate:
ViewController.h
#import <UIKit/UIKit.h>
#protocol InitStackDelegate <NSObject>
#required
-(void)initstack:(NSInteger)amount;
#end
#interface ViewController : UIViewController{
IBOutlet UITextField *amountTextField;
__unsafe_unretained id<InitStackDelegate> delegate;
}
- (IBAction)init:(id)sender;
#property (nonatomic,assign)id delegate;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize delegate;
- (IBAction)init:(id)sender {
//send the delegate
[delegate initstack:[amountTextField.text intValue]];
}
AppDelegate.h
#import <UIKit/UIKit.h>
#import "ViewController.h"
#interface AppDelegate : UIResponder <UIApplicationDelegate,InitStackDelegate> {
}
#property (strong, nonatomic) UIWindow *window;
#property (strong,nonatomic) ViewController *myView;
#end
AppDelegate.m
#import "AppDelegate.h"
#implementation AppDelegate
#synthesize window;
#synthesize myView;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
// Override point for customization after application launch.
//..... push second controller into navigation stack
myView.delegate = self;
return YES;
}
...
#pragma mark Delegate Method
-(void)initstack:(NSInteger)amount{
NSInteger test;
}
#end
When i hit the button i get to (IBAction) init but then the delegate do nothing. I set a breakpoint in AppDelegate.m but it is never reached. Any help?
thx
Mario
In you App Delegate, when you set myView.delegate=self myView doesn't actually point to anything!
You need to set myView to point to your ViewController.
Use this in didFinishLaunchingWithOptions
myView = (ViewController *)self.window.rootViewController;
myView.delegate = self;