How to properly add "handleOpenURL" method on iPhone App Delegate - iphone

I am pretty new to objective-c.
I am working on a Video App. I am trying to connect my App with Facebook.
I am trying to make the "Single Sign On" to work. The flow seems to be working fine:
Facebook App is loaded.
I press "Allow" or "Don't Allow" and my App is being put to foreground.
But, for some reason I cannot make the "handleOpenURL" to work. I followed Facebook instructions and added this method to my class: AVCamViewController (this class is taken from the AVFoundation example App):
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSLog(#"Facebook handleOpenURL");
return [facebook handleOpenURL:url];
}
The method is never called.
I guess I am doing something wrong related with the App delegate.
The problem, I don't know exactly what is App delegate and how can I access it?
Can anyone help me to properly use the "handleOpenURL" in my App?
Thanks,
Guy

The handleOpenURL: method is part of the UIApplicationDelegate protocol. You need to implement this method in your application delegate.

Related

How Can I capture the event before my App is minimized?

I need to close some resources I am using when the App is minimized by clicking on Home Button.
Attention, I don't want to intercept the Home button, I know it is not allowed by Apple
thanks
Use the delegate method - (void)applicationDidEnterBackground:(UIApplication *)application which is in appdelegate class. Whenever user taps the home button, this method will be called. for more details, check apple documentation. You can use applicationWillResignActive: in case you want to detect an incoming phone call or sms as well along with app minimizing.
You want to look at the UIApplicationDelegate (reference). Specifically, applicationWillResignActive and applicationDidEnterBackground should be what you want.
From the Apple docs, this also goes into more detail with examples - App States and Multitasking.

fbDidLogin or fbDidNotLogin not called

I am trying to integrate facebook login in my existing app. I have the openURL and handleOpenURL methods in AppDelegate.m, but i initialize facebook object in one of the view Controller on click of a button. so my fbDidLogin method is in the viewController, which never gets called. Neither is the fbDidNotLogin is called.
Is it something wrong I am doing?
I had the same problem and it was because i hadnĀ“t set the URL types in the info.plist like it says on the tutorial http://developers.facebook.com/docs/mobile/ios/build/#register
And I have forgotten to implement the only method in the AppDelegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[FacebookService sharedInstance].facebook handleOpenURL:url];
}
FacebookService - is my wrapper singletone class, that contains instance og facebook
the error was the same

Animation on iPhone app closing, like the shutter on camera app

I'd like my app to do an animation just before close, exactly like the official Camera app from Apple, that "closes the shutter" before closing itself. Is is possible or is this a private and undocumented API?
Thank you in advance!
There is no official way for your app to delay its closing after the user taps the home button. Apple wants users to be able to quit out of apps quickly and at anytime. However, you do get notified when your app is closing, and you do get a chance to run some code. I can't tell you for sure of any UI stuff would work, but the spot to try it is in your UIApplicationDelegate (AppDelegate) class. The methods you're interested in are:
- (void)applicationWillResignActive:(UIApplication *)application {
// Try some UI stuff here
}
Or:
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
I'm assuming the UI will change as the app window is animating away. Let us know if it works!

iPhone Application Themes

I tried using a multi-value settings bundle to change the view. I would do the if statements in the applicationdidfinishloading in the application delegate. Apparently the method isn't called every time the app is loaded, and it would not work correctly.
If anyone has done this, or has any suggestions, links to tutorials. I would really appreciate it. I'm just trying to load views (nibs) based on user preference.
I think you can put your code in
- (void)applicationDidBecomeActive:(UIApplication *)application
or
- (void)applicationWillEnterForeground:(UIApplication *)application
methods also because from iOS 4.0 due to multitasking your app is just in the background state so it wont call applicationdidfinishloading method when the user presses the icon of your app again.

Where does UIApplication's handleOpenURL 'Return' to exactly?

I'm working on a handling a custom URL Scheme in an app and am trying to sort out:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
I'm passing and successfully parsing a URL into an NSDictionary in my app but wondering "what now?" handleOpenURL returns a BOOL but to what? It's hard for me to debug as I haven't figure out how to have debugger running on device when it fires.
All I do know is that applicationDidFinishLaunching completes before handleOpenURL and it appears as though my rootViewController is on screen.
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Load data
[self initializeData];
// Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
Anyway, so, now I have this NSDictionary object in my appDelegate, how would you pass it to the rootViewController so it can do something with it in its detail view? Would I call
[[navigationController topViewController] addItemWithDictionary:theDictionary];
before handleOpenURL's return YES; Or, should I create an NSDictionary property in my appDelegate and then after "Return YES;" retrieve it from my rootViewController (or detailViewController - haven't worked out which yet). If so what's the trigger? It's not clear to me where handleOpenUrl's returns are heading...and what, if any, value they have to me.
Thanks!
Take a look at the suggestion here about didFinishLaunchingWithOptions
http://www.iphonedevsdk.com/forum/iphone-sdk-development/31742-handleopenurl-not-called.html
There are a couple of approaches I've used to pass data around, and depending on the conditions I mix it up.
Keep a global around so you don't have to worry about passing.
Register/post your data using the Observer pattern with a Notification object using the notification message center.
Save URLs to NSUserDefaults (also a dictionary, but you don't have to manage it).
Recently I had to do something similar on a UIWebView and the handling of filtering some URL data. I had to subclass WebViewCache and setSharedCache on the NSURL. I strongly suspect this would apply to your problem as well by retrieving the data with shouldStartLoadWithRequest.
a handy tip for debugging openurl from other apps or mobile safari (non jailbroken device) is to subclass UIApplication and override a few undocumented methods, sorry i dont remember names offhand but you can dig them up at ericasadun.com, the names will be fairly obvious.
when you launch the app through xcode and hit home springboard doesnt kill the process because it was started by xcode (afaik) so you can launch other apps and call openurl while still being attached to the debugger.
I think I may have answered my own question but if you have other ideas I'd love to hear them!
I think I need to continue processing in handleOpenURL and turn the dictionary into an object that is then added to my appDelegate's array that rootViewController is using to build it's table view. Obviously need to work out some validation & confirmation on user's part before auto populating array. I guess that would also happen within confines of handleOpenURL?