iPhone FBConnectDialog box disappears - iphone

So I've been trying to integrate FB with my iPhone application with FB connect. However, after using the tutorial (http://www.mobisoftinfotech.com/blog/iphone/iphone-fbconnect-facebook-connect-tutorial/), it seems when the FBDialog box is called, it pops onto the screen for a few seconds and then disappears. I'm not sure what is going, becuase IT WORKS in the Simulator perfectly. I have an iPhone 4 device. Here is my code below:
(void)viewDidLoad {
[super viewDidLoad];
session = [[FBSession sessionForApplication:#"MYAPIKEY" secret:#"MYSECRET" delegate:self] retain];
FBLoginButton *button = [[[FBLoginButton alloc] init] autorelease];
[button setFrame:CGRectMake(100, 100, 100, 50)];
[self.view addSubview:button];
}

Nevermind, I'm sorry for being a noob. Turns out my three hour struggle to figure this out was a complete waste. The problem -- my iPhone wasn't connected to Wifi/cell network.

Related

Perform selector:withObject:afterDelay firing immediately, no delay

I have a very strange error that I have never seen before. I have used this code hundreds of times before, but for some reason, the afterDelay is being completely disregarded.
My Code:
- (void)runIntro
{
if([self introDone])return;
UIImageView* back = [[UIImageView alloc] initWithFrame:[[AppDelegate shared] frame]];
[back setImage:[[AppDelegate shared] bgImage]];
[back setContentMode:UIViewContentModeScaleAspectFill];
[self.view addSubview:back];
UIImageView* target = [[UIImageView alloc] initWithFrame:CGRectMake(([[AppDelegate shared] width]-250)/2.0, ([[AppDelegate shared] height]-350)/2.0, 250, 72)];
[target setImage:[UIImage imageNamed:#"bpside.png"]];
[self.view addSubview:target];
Parabolic* wally = [[Parabolic alloc] initWithFrame:CGRectMake(([[AppDelegate shared] width]-200)/2.0, ([[AppDelegate shared] height]-314)/2.0+250, 200, 200)];
[wally setImage:[UIImage imageNamed:#"wallyside1.png"]];
[self.view addSubview:wally];
[self performSelector:#selector(moveWallyIntro:) withObject:wally afterDelay:1];
[self performSelector:#selector(moveWallyIntro:) withObject:wally afterDelay:2];
}
- (void)moveWallyIntro:(Parabolic*)wally
{
[wally runPBM:50 withDY:300 withDuration:0.5];
}
I know that all of the other code is working properly, but for whatever reason, the selectors are being performed immediately, which causes a major problem. This code is being run at the end of the viewWillAppear method. I have programmed this way many times before and this is the first time I've seen this happen.
UPDATE:
If I remove the code that adds the back UIImageView, this no longer is a problem. How can I add a giant image (3000x2000) in aspect fill format like this so it doesn't cause the program to hang? I'm using the same background image for iphone, ipad, etc., so it needs to be large for the retina iPads...

How to consume UI Events while loading data in the background

I have a little iPhone app that loads data from a web service. To make sure that nothing goes wrong while loading the data I create a semi-transparent view over the app and use CFRunloopRun() to wait until all the data is loaded in the background. This is the code for that:
self.connection = [[[NSURLConnection alloc] initWithRequest:request delegate:self] autorelease];
// Now show an animation
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
UIView *window = [[UIApplication sharedApplication] keyWindow];
UIView *shield = [[UIView alloc] initWithFrame:window.bounds];
shield.backgroundColor = [UIColor blackColor];
shield.alpha = 0.5f;
[window addSubview:shield];
spinner.center = shield.center;
[shield addSubview:spinner];
spinner.hidden = NO;
NSLog( #"JCL.callServerWithRequest(), spinner view: %#, shield view: %#, window: %#", spinner, shield, window );
[spinner startAnimating];
// Hand over to the Runnloop to wait
CFRunLoopRun();
[spinner stopAnimating];
[spinner removeFromSuperview];
[spinner release];
[shield removeFromSuperview];
[shield release];
This works fine except that any clicks on a button somewhere is played after the loading so if the users clicks on the download button twice he will do the download twice as well.
Any idea how to consume the UI events before the shield is removed.
Thanks - Andy
Try it without messing with runloops. I suspect that the UI events are coming in to the normal loop on the window but not being processed until your custom loop returns, at which point the "shield" view is no longer there to catch them. If you put the shield in place and then let the main runloop handle things, the shield should catch them all as normal.
Thanks to Anomie I finally tried out to go without the CFRunLoopRun() and it is quite difficult because the execution is split into two parts: - the Invocation and the Return of the Result through a callback. But then I shot myself in the proverbial foot because I tried to block the returning thread to slow down the execution which did not work because that was executed again in the main thread.
Eventually I did slow down the Web Service and then everything worked as expected.

game center not working on ipod/iphone

Hi all
Working on a universal build for an iphone/ipod/ipad app. I was trying to get game center working within this app. I now have the game center working on the ipad but for some reason it still wont work on the ipod/iphone and i have no idea why.
highScoreVC=[[UIViewController alloc] init];
GKLeaderboardViewController *leaderboardController = [[[GKLeaderboardViewController alloc] init] autorelease];
if (leaderboardController != nil)
{
leaderboardController.leaderboardDelegate = self;
[[[CCDirector sharedDirector] openGLView] addSubview:highScoreVC.view];
[highScoreVC presentModalViewController:leaderboardController animated: YES];
}
this is my code for displaying the leaderboard and it does work everytime for ipad but as i said not for other devices. the code is still being called the same as for ipad so i have no clue why it is not displaying. any ideas why this would be? cheers
As far as I'm concerned, [GKLeaderboardViewController init] will return nil if the device is not authenticated with Game Center by that point. Are you sure you are correctly authenticated on the devices causing problems?
I suspect there may be some issues with how your UIKit items for Game Center are being displayed if they are working fine on the iPad but not iPhone/iPod. I experienced similar sounding issues when converting an app to universal.
If you create a new standalone iPhone/iPod project just for testing does game center display fine?
ok i got it working in the end.
cocos2d 0.99.5 has indeed made some changes that to how this works. the following code displays the leaderboard correctly
-(UIViewController*) getRootViewController{
return (UIViewController*)([(BubbleDreamsAppDelegate*) [[UIApplication sharedApplication] delegate] viewController]);
}
and then
highScoreVC = [self getRootViewController];
GKLeaderboardViewController *leaderboardController = [[[GKLeaderboardViewController alloc] init] autorelease];
if (leaderboardController != nil)
{
leaderboardController.leaderboardDelegate = self;
[highScoreVC presentModalViewController:leaderboardController animated: YES];
}
hope this helps anyone that gets stuck with same problem

MPMoviePlayerViewController quits unexpectedly

I'm trying to get videos to play from my server on the iPhone device. I'm using the following method to do so, however, it only works in the simulator; and on my iPhone 4. It doesn't work on iPhone 3G?
If I call this method on the iPhone 3G, it opens the video modal screen, starts to load the video, and then closes the modal screen abruptly. No errors are shown in the console.
The iPhone 3G has version 4.0 installed. My iPhone 4 has version 4.1.
Has anyone else experienced this?
-(IBAction)playMedia{
NSString* url = [self.data objectForKey:#"url"];
//initialize the movie player
self.moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]];
//show a background image while the user waits
moviePlayerViewController.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background.png"]];
moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
//show the movie
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
[moviePlayerViewController release];
}
ok I got video to work on both iPhone 4 and iPhone 3G. Basically the issue was the file format. I was playing a .mov file. When I changed the format to .mp4, it now works on both devices. No change in code.
Hope this helps others with the same issue.
I'd do the above a little differently:
-(IBAction)playMedia{
NSString* url = [self.data objectForKey:#"url"];
//initialize the movie player
MPMoviePlayerViewController *tmpPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:url]];
self.moviePlayerViewController = tmpPlayer;
//show a background image while the user waits
UIColor *tmpColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background.png"]];
self.moviePlayerViewController.view.backgroundColor = tmpColor;
self.moviePlayerViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
//show the movie
[self presentMoviePlayerViewControllerAnimated:self.moviePlayerViewController];
[tmpPlayer release];
[tmpColor release];
}

How do I get a UIView to appear instantly?

I'm trying to create an activity indicator in iPhone app. The problem is that I cannot get it to appear before the actual task i want it to diplay during is already done. Is there something funky about the order in which the iPhone does stuff?
Here is my problematic code (in my app delegate):
-(BOOL)showProgressView: (NSString *) message {
self.progress = [[UIView alloc] initWithFrame:window.frame];
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"squircle.png"]];
[img setAlpha:0.5];
[img setFrame:CGRectMake(94, 173, 133, 133)];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(51.5, 51.5, 30, 30)];
spinner.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[img addSubview:spinner];
[self.progress addSubview:img];
[spinner startAnimating];
[img release];
[spinner release];
[window addSubview:self.progress];
return YES;
}
I then call this code like this:
if ([appDelegate showProgressView:#"Loading..:"])
{
//My actual code loads data and stuff here but that is not important
//drawCtrl is a UIViewController subclass that is instantiated here
UINavigationController *navController = [appDelegate navigationController];
[navController pushViewController:drawCtrl animated:YES];
[drawCtrl release];
}
The problem is that my activity indicator does not appear until the new view controller is pushed onto the navController's stack. Can I control this in some way?
Thanks in advance!
-Mats
You need to call your loading method periodically via a timer. UI changes require a trip through the event loop to be seen. I have done this usually in a timer I set up in the AppDelegate, it calls the "methodThatTakesSomeTime" every n seconds, the "methodThatTakesSomeTime" method does some work for a specified time slice and then exits which is usually about the same as the timer trigger time. This gives the event loop time to refresh the UI and also give your method time to do its stuff.
Takes some fiddling with keeping the state of the "methodThatTakesSomeTime" so it can continue on its way, but that is what it takes.