UIApplication delegate method is not called - iphone

I have a problem integrating Facebook SDK 3.2 with my app, my app goes to facebook app for approval and login, but when
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation;
needs to be called when facebook authorization is done, it simply skips it.
It works great when I force webView facebook login via modal viewcontroller, but when I want to use installed facebook app/safari it just doesn't work.
Any suggestions?
Thank you.

Make sure you put UIApplicationDelegate in interface declaration.
#interface AppDelegate : NSObject <UIApplicationDelegate>
Also verify its right App delegate class
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, #"AppDelegate");
[pool release];
return retVal;
}
Also add fb Id in plist.

Related

EXC_BAD_ACCESS when opening modal view

I'm having a problem with my iPhone App, I'm getting EXC_BAD_ACCESS, I had some memory leaks, but these are now fixed, so I'm not sure whats going on. I realise that I haven't provide a lot of information, but I really don't know whats happening.
The initial screen opens up where I have a number of buttons. Tapping on the first button, which runs the following code and opens up a modal view:
-(IBAction)newWorkoutButton
{
newWorkoutViewController .loadedFromRootViewController = #"YES";
[self presentModalViewController:newWorkoutViewController animated:YES];
}
The screen freezes and the is in the code below:
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
#import <CoreLocation/CoreLocation.h>
int main(int argc, char *argv[])
{
Method getDistanceFrom = class_getInstanceMethod([CLLocation class], #selector(getDistanceFrom:));
class_addMethod([CLLocation class], #selector(distanceFromLocation:), method_getImplementation(getDistanceFrom), method_getTypeEncoding(getDistanceFrom));
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil); // ERROR HAPPENING HERE
[pool release];
return retVal;
}
Like Aleks suggested you can try to find the zombie like this:
I find this alternative more convenient:
Click the "Run Button Dropdown"
From the list choose Profile
The program "Instruments" should open where you can also choose Zombies
Now you can interact with your app and try to cause the error
As soon as the error happens you should get a hint on when your object was released and therefore deallocated.
(source: dimzzy.com)

Implement auto log-off feature in Iphone

I am making an application which logs in using some username and password. Now when i am logged in succesfully I want my application to be logged out automatically if no interaction with the application found for 10-12 minutes.
Can anybody guide me how can i achieve this ??
Help with some code will be really appreciated.
Thanks
The Thing you want to implement is called SESSION MANAGEMENT.You have to subclass the UIApplication.
#interface MyUIApp : UIApplication {
}
In this class you have to reset the timer each time. Also you have to check if the application is responded or not with this.If the idleTimer is Exceeded then push the viewController to your login view.
- (UIResponder *)nextResponder {
[self resetIdleTimer];
return [super nextResponder];
}
Also you have to change the main class file with this:-
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSString* appClass = #"MyUIApp";
NSString* delegateClass = nil;
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, appClass, delegateClass);
[pool release];
return retVal;
}

fbDidLogin not called - iOS

I'm trying to implement facebook to my iOS app for a school project however I ran into a bit of a snag, namely the fbDidLogin method is not called.
I have created a sample object called FBFetcher as so:
#interface FBFetcher : NSObject <FBDialogDelegate,FBSessionDelegate,FBRequestDelegate> {
Facebook *facebook;
FBFetcher *facebookFetcher;
}
-(void)login;
#property (retain) Facebook *facebook;
#property (retain) FBFetcher *facebookFetcher;
#end
In the FBFetcher.m:
#implementation FBFetcher
#synthesize facebookFetcher,facebook;
-(void)login{
facebook = [[Facebook alloc] initWithAppId:#"...."];
NSArray *permissions = [[NSArray arrayWithObjects: #"offline_access",#"user_about_me", nil] retain];
[facebook authorize:permissions delegate:self];
}
-(void)fbDidLogin {
NSLog(#"Erfolgreich eingeloggt....");
}
#end
In my app delegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [[[controller facebookFetcher] facebook] handleOpenURL:url];
}
I have a separate view controller with n action tied to a UIButton:
facebookFetcher = [[FBFetcher alloc] init];
[facebookFetcher login];
I can access the login and authorization page, however the method fbDidLogin never gets called. Any suggestions?
The method never gets called because when you authorize, you are doing it in Safari. To take care of this, which I think is a bug from Facebook SDK by the way, open the facebook.m file and find the following line:
[self authorizeWithFBAppAuth:YES safariAuth:YES];
and change it to
[self authorizeWithFBAppAuth:NO safariAuth:NO];
This way you will never be sent to Safari, but everything will be done in a dialog.
Just test it and you'll see that the fbDidLogin method will get called.
Hope it will help
What about
- (void)fbDidNotLogin:(BOOL)cancelled
Does that get called?
Look for this function in Facebook.m. This is where Facebook calls your fbDidLogin function. First make sure this is being called, then debug into it. Make sure you've spelled/defined fbDidLogin correctly in your session delegate (no parameters). If not the respondsToSelector will fail and never call your delegate's function.
- (void)fbDialogLogin:(NSString *)token expirationDate:(NSDate *)expirationDate
{
self.accessToken = token;
self.expirationDate = expirationDate;
if ([self.sessionDelegate respondsToSelector:#selector(fbDidLogin)])
{
[_sessionDelegate fbDidLogin];
}
}

Problems in TTTableview class using Three20 in iPhone?

Now I am using Three20 in my apps. I have a problem, when I run the application with MainWindow.xib, the TTTableview class isn't called. But without MainWindow.xib it would call the TTTableview class. I don't know why it's happening. Please help me out.
Thanks.
In your AppDelegate code
delete the mainWindow.xib
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
if (![navigator restoreViewControllers]) {
[navigator openURLAction:[TTURLAction actionWithURLPath:kAppRootURLPath]];
}
}
In main.m
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, #"YOURAppDelegate");
[pool release];
return retVal;
}

iPhone - Preventing Sleep while using applicationMusicPlayer in MPMusicPlayerController

I am trying to disable the automated sleeping of iPhone for certain period in my app.
Used [[UIApplication sharedApplication] setIdleTimerDisabled:YES] which works fine as long as I play no music.
But when I play music the Idle Timer seems to get reactivated.
I have tried all kinds of tricks from NSTimer firing silent sounds every 10 second etc but nothing works.
Would welcome any suggestion or thoughts on making this happen.
The way to fix this is to first subclass UIApplication, override the setIdleTimerDisabled method and make it do nothing. Then, add a couple of your own methods that you'll call from your application instead of using the normal setter. By doing this you will ignore all messages that might change the idle timer aside from the custom method calls you make yourself. Here's how you do it:
Edit your main.m file to use a custom UIApplication subclass:
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSString* appClass = #"CustomUIApplicationSubclass";
NSString* delegateClass = nil;
int retVal = UIApplicationMain(argc, argv, appClass, delegateClass);
[pool release];
return retVal;
}
Then define your UIApplication subclass:
#interface CustomUIApplicationSubclass : UIApplication {
}
- (void)disableIdleTimer;
- (void)enableIdleTimer;
#end
#implementation CustomUIApplicationSubclass
- (void)setIdleTimerDisabled:(BOOL)disabled
{
// do nothing! take that stupid ipod controller!
}
- (void)enableIdleTimer
{
[super setIdleTimerDisabled:NO];
}
- (void)disableIdleTimer
{
[super setIdleTimerDisabled:YES];
}
#end
This will force the iPod controller to use your custom UIApplication instance which does no longer does anything when the normal setIdleTimerDisabled method is called.