FINAL SOLUTION THAT I USED: This method did not work out very well for me, and I only had 2 variables which had to be transferred so I decided to use NSNotificationCenter to send the objects. Please use this ONLY if you have very little objects to transfer, or else it could get extremely messy! If you want to learn more about this, I recommend that you check out this question: pass NSString variable to other class with NSNotification Good Luck!
I'm trying to access data from my App Delegate, but I'm always getting a (null).
EDIT: If anyone wants the full code, here it is: http://pastebin.com/hNUPMcvB
Here's the code in my AppDelegate:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// Stop Location Services
[locationManager stopUpdatingLocation];
// Some Reverse Geocoding...
CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
for (CLPlacemark * placemark in placemarks) {
City = [[placemark locality] stringByReplacingOccurrencesOfString:@" " withString:@"+"];
State = [[placemark administrativeArea] stringByReplacingOccurrencesOfString:@" " withString:@"+"];
Final = [NSString stringWithFormat:@"%@,%@", City, State];
currentLocation = [NSString stringWithFormat:@"%@", Final];
[self everythingelse];
NSLog(@"AAA%@", currentLocation);
}
}
];
}
This is how I'm accessing the code from my other View Controller:
ForecasterAppDelegate *BossMan = (ForecasterAppDelegate *)[[UIApplication sharedApplication] delegate];
CurrentLocation = BossMan.currentLocation;
NSLog(@"CCC%@", CurrentLocation);
It always logs as CCC(null). In my AppDelegate, it comes out right, but in the other view controller its not. I'm either making a small mistake or a huge one, any help would be great!
EDIT: Here are my header files:
My App Delegate .h:
@interface ForecasterAppDelegate : UIResponder <UIApplicationDelegate, CLLocationManagerDelegate> {
UIStoryboard *storyboard;
NSString *City, *State, *Final, *currentLocation;
NSMutableString *FinalQuery;
CLLocationManager *locationManager;
CLPlacemark * myPlacemark;
}
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic,retain) CLLocationManager *locationManager;
@property (nonatomic, retain) NSMutableString *FinalQuery;
@property (strong, nonatomic) NSString *currentLocation;
@property (nonatomic, retain) NSString *Final;
and here is my View Controller .h file:
@interface View1 : UIViewController <CLLocationManagerDelegate, LocationDamn> {
CLLocationManager *locationManager;
CLPlacemark * myPlacemark;
NSString *launchpath;
NSString *City, *State, *condition, *Final, *degreesign, *changeLocation, *currentLocations;
}
@property (nonatomic,retain) CLLocationManager *locationManager;
@property (nonatomic,retain) IBOutlet UILabel *currentTempLabel, *highTempLabel, *lowTempLabel, *conditionsLabel, *cityLabel, *day2c, *day3c, *currentconditions;
@property (nonatomic,retain) IBOutlet NSString *currentLocations;
@end
In my viewdidload of my ViewController, I have this:
[self performSelector:@selector(DoSomethingCool) withObject:nil afterDelay:1.5];
so that the location manager has some time to get the location.