Reputation: 4110
I have a viewcontroller that has code to implement the Facebook window. the problem is that to run the code, I need this url:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
self.openedURL = url;
// attempt to extract a token from the url
return [FBSession.activeSession handleOpenURL:url];
}
...and as I have understood it can only be run in the app delegate, but I need it to get the url. If I simply add it to the delegate it is not called, and I don't know when it is called and how. any suggestions??
Upvotes: 0
Views: 115
Reputation: 2678
If you need to see the url you can use a global variable to store it from this function and use it later, let us assume you have a singleton called appData declare a static variable
.h file
+(appData*)sharedAppData;
@property (nonatomic,retain) nsurl * myUrl;
in the .m file
static appData* = nil;
initFunction {
if(! appData) { appData = [[appData alloc] init];}
}
+(appData*)sharedAppData{
return appData;
}
in the init function initialize this object so in any where in the system you can access your this data by
appData * data = [appData sharedData]; data.myurl =.... nslog(@"my url %@",data.url);
Upvotes: 0
Reputation: 104092
If you need to use a property of the app delegate in another class you can use the following code (assuming the the name of your app delegate class is AppDelegate) in your view controller class:
NSURL *theURL = [(AppDelegate *)[[UIApplication shardApplication]delegate] openedURL];
I'm assuming here, that you want to pass this URL along to your controller. You also need to import the AppDelegate.h file into your controller.
Upvotes: 1