does not submit the score in gamecenter - iphone

i want input gamecenter in my app
so i make new project "gamecenter" for test gamecenter
i referenced "http://www.youtube.com/watch?v=9avpP0hYwik" video. but
I use xcode 4.2 so delete of "autorelease"
app does not submit the score at gamecenterhelp plz :-(
my code is
viewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
IBOutlet UILabel *scoreText;
int *scoreInt;
}
-(IBAction)subScore:(id)sender;
-(IBAction)showLeader:(id)sender;
-(IBAction)addScore:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#import <Gamekit/Gamekit.h>
#implementation ViewController
-(IBAction)subScore:(id)sender
{
GKScore *scoreReporter = [[GKScore alloc] initWithCategory:#"1234567"];
scoreReporter.value = scoreInt;
[scoreReporter reportScoreWithCompletionHandler:^(NSError *error) {
if (error != nil)
{
NSLog(#"failed");
}
else
{
NSLog(#"Succeeded");
}
}];
}
-(IBAction)showLeader:(id)sender
{
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil)
{
leaderboardController.leaderboardDelegate = self;
[self presentModalViewController:leaderboardController animated:YES];
}
}
-(void)leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
[self dismissModalViewControllerAnimated:YES];
}
-(IBAction)addScore:(id)sender
{
scoreInt +=1;
NSString *clicks = [NSString stringWithFormat:#"%d", scoreInt];
scoreText.text = clicks;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
if (error == nil)
{
NSLog(#"Authentication Successful!");
}
else
{
NSLog(#"Authentication Failed!");
}
}];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#end

Are you sure your leaderboard category id is correct?
Do you get any error messages in your request blocks?
If you get no response to your asynchronous request blocks, it means gamecenter is not ready to handle your request. You need to wait for a few hours if you just created the leaderboard.

Related

Twitter implementation. in login of iPhone application

I am new in twitter implementation, in my application there is one login screen, I want to give an option of twitter login also ,means user can also login from his twitter account.
please give some useful tips, How to do this.
You can use TwitterShare files.
TwitterShare.h
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#import <Twitter/Twitter.h>
#import <Accounts/Accounts.h>
#interface TwitterShare : UIViewController
{
TWTweetComposeViewController *_tweetSheet;
}
#property (nonatomic, retain) TWTweetComposeViewController *_tweetSheet;
- (void)buildTweetSheet:(UIView*) viewOnWhichToShow;
-(void)share:(UIImage*)imageToUpload viewOnWhichToShow:(UIView*) viewOnWhichToShow;
#end
TwitterShare.m
#import <MobileCoreServices/UTCoreTypes.h>
#import "TwitterShare.h"
#import "ProgressIndicator.h"
#implementation TwitterShare
#synthesize _tweetSheet;
#pragma mark -
#pragma mark View methods
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
#pragma mark -
#pragma mark Showing Tweet Sheet
- (void)buildTweetSheet:(UIView*) viewOnWhichToShow
{
/* make instance of tweet sheet */
_tweetSheet = [[TWTweetComposeViewController alloc] init];
/* Specify the completion handler */
TWTweetComposeViewControllerCompletionHandler completionHandler = ^(TWTweetComposeViewControllerResult result)
{
[self dismissModalViewControllerAnimated:YES];
NSString *info;
if(result == TWTweetComposeViewControllerResultDone)
{
info = [NSString stringWithFormat:#"Saved"];
ProgressIndicator *indicator = [[ProgressIndicator alloc]init];
[indicator tweetSuccessOrFail:info view:viewOnWhichToShow];
[indicator release];
indicator = nil;
}
else if(result == TWTweetComposeViewControllerResultCancelled)
{
// statements if tweet sheet cancelled.
}
[_tweetSheet release];
_tweetSheet = nil;
};
[_tweetSheet setCompletionHandler:completionHandler];
}
#pragma mark -
#pragma mark Share to Twitter
-(void)share:(UIImage*)imageToUpload viewOnWhichToShow:(UIView *)viewOnWhichToShow
{
[self setView:viewOnWhichToShow];
[self buildTweetSheet:viewOnWhichToShow];
/* add Image To _tweetSheet */
/* Show our tweet sheet */
[_tweetSheet addImage:imageToUpload];
[self presentModalViewController:_tweetSheet animated:YES ];
}
Looks like you have not visited (and bookmarked) Twitter Developers and its documentation yet :
Sign in with Twitter : https://dev.twitter.com/docs/auth/implementing-sign-twitter
SSO with iOS >= iOS5 : https://dev.twitter.com/docs/ios#Single_Sign-On

Showing ads on every view automatically in iPhone

I'm implementing Mobclix in my app, and when following the instructions, it tells us to properly release and dealloc the adview. It also tells us that when the view appears, you should call refreshAds and when it disappears you should pause refresh ads:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.adView resumeAdAutoRefresh];
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.adView pauseAdAutoRefresh];
}
#implementation RootViewController
- (void)viewDidUnload {
[self.adView cancelAd];
self.adView.delegate = nil;
self.adView = nil;
}
- (void)dealloc {
[self.adView cancelAd];
self.adView.delegate = nil;
self.adView = nil;
[super dealloc];
}
#end
My question is that I have a lot of view controllers, so it would be inconvenient to implement these things on each view. Is there anyway I can call these methods in one place and have it work for all views?
What you can do is subclass UIViewController and have all your viewControllers to inherit these things.
So basically you could have AdsViewController.h wich will look like
#import <Foundation/Foundation.h?
#interface AdsViewController: UIViewController {
}
#property (nonatomic, retain) <#AdsViewType#> *adsView;
#end
and your AdsViewController.m will have to look pretty much like this
#import "AdsViewController.h"
#implementation AdsViewController
#synthesize adsView = _adsView;
- (id)init {
self = [super init];
if (self) {
_adsView = [[<#AdsViewType#> alloc] init];
_adsView.delegate = self;
}
return self;
}
- (void)viewDidUnload {
[self.adView cancelAd];
self.adView = nil;
[super viewDidUnload];
}
- (void)dealloc {
[self.adView cancelAd];
self.adsView = nil;
[super dealloc];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.adView resumeAdAutoRefresh];
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.adView pauseAdAutoRefresh];
}
#end
After this have all your viewControllers to subclass this instead of UIViewController. Hope this helps.

In Xcode an error says 'activities' undeclared

Hello I'm new to developing and I was wondering if any of you pros would know how to fix this issue.
My code is Below: InstaTwitViewController.m:
#import "InstaTwitViewController.h"
#implementation InstaTwitViewController
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
activities = [[NSArray alloc] initWithObjects:#"sleeping",
#"eating", #"working", #"thinking", #"crying", #"begging",
#"leaving", #"shopping", #"hello worlding", nil];
feelings = [[NSArray alloc] initWithObjects: #"awesome",
#"sad", #"happy", #"ambivalent", #"nauseous", #"psyched",
#"confused", #"hopeful", #"anxious", nil];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[activities release];
[feelings release];
[super dealloc];
}
- (NSInteger)numberOfComponentsInPickerView: (UIPickerView *)
pickerView {
return 2;
}
- (NSInteger)pickerView:(UIPickerView *)
pickerViewnumberOfRowsInComponent :(NSInteger)component {
if (component == 0) {
return [activities count];
}
else {
return [feelings count];
}
}
#end
Next to [activities count] and [activities release] it states an error "'activities' undeclared"
InstaTwitViewController.h:
//
// InstaTwitViewController.h
// InstaTwit
//
// Created by John Bridge on 5/2/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface InstaTwitViewController : UIViewController
<UIPickerViewDataSource, UIPickerViewDelegate> {
NSArray* actvities;
NSArray* feelings;
}
#end
EDIT
You have a typo in your property declaration.
actvities should be activities, with an i.
You should be more careful while coding, and reading your own code...
EDIT END
Apparently, you haven't declared the activities variable. That's why XCode says it's undeclared...
I guess it should be an NSArray... You need to declare the variable in your class interface (the header file).
Something like:
#interface InstaTwitViewController: UIViewController
{
NSArray * activities;
}
#end
Then, in your implementation, you need to allocate it, for instance in the init method:
- ( id )initWithNibName: ( NSString * )nibNameOrNil bundle: ( NSBundle * )nibBundleOrNil
{
if( ( self = [ super initWithNibName: nibNameOrNil bundle: nibBundleOrNil ] ) )
{
activities = [ NSArray new ];
}
return self;
}
And don't forget to release it in the dealloc method:
- ( void )dealloc
{
[ activities release ];
[ super dealloc ];
}
Remove the /* and */ code before and after the viewDidLoad method, and declare an NSArray called activities in your .h file.
NSArray *activities;
EDIT---- As MacMade said, just fix the spelling mistake!

UIImageView subclass with CGRectIntersectsRect - help!

The title of this question should be pretty self explanatory. I am making an app that involves multiple UIImageViews that serve the same purpose. They are merely different sizes. Anyway, I decided that the best solution was to make UIImageView subclasses, link the subcalsses in IB, and work from there. My code should explain this better -
#define kPausedStatePaused 1
#define kPausedStatePlay 2
#import "Game.h"
#import "ScoreSystem.h"
#interface Doctor : UIImageView
{
}
#end
#interface Ground : UIImageView
{
}
#end
#interface Wall : UIImageView
{
}
#end
#interface Electric_Wire : UIImageView
{
}
#end
#implementation Game
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
- (IBAction)pause {
UIAlertView *pause = [[UIAlertView alloc] initWithTitle:#"Pause" message:nil delegate:self cancelButtonTitle:#"Quit" otherButtonTitles:#"Play", nil];
[pause show];
[pause release];
pauseint = kPausedStatePaused;
}
- (void)viewDidAppear {
pauseint = kPausedStatePlay;
}
- (void)loop {
Doctor *doctorview;
Ground *groundview;
if (CGRectIntersectsRect(doctorview, groundview)) {
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([alertView.title isEqual:#"Pause"]) {
if(buttonIndex == 0)
[self dismissModalViewControllerAnimated:YES];
pauseint = kPausedStatePlay;
}
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
Unsurprisingly, Xcode gave me an "incompatible type for CGRectIntersectsRect" error.
You must pass view's frame, not the view's themselves to that function:
CGRectIntersectsRect(doctorview.frame, groundview.frame)

Return to RootController is crashing my app

My application is crashing, I think, in RootController.m and I don't know why. It occurs when I am in any view controller and I push the back button. It briefly returns to RootController and then it crashes. There is no messages on the console. I don't think it is the ViewController as I have tried more than one.
Here is the code.
#import "confirmViewController.h"
#implementation confirmViewController
#synthesize lblStatus;
#synthesize lblCardType;
#synthesize lblCardNumber;
#synthesize lblExpires;
#synthesize lblAmount;
#synthesize lblApproval;
#synthesize strConfirmation;
#synthesize strCardNumber;
#synthesize strExpires;
#synthesize strAmount;
#synthesize strApproval;
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
//prepare confirmation, all that is needed is the first string
NSArray *strings = [strConfirmation componentsSeparatedByString: #","];
NSString *strPreParsed = [strings objectAtIndex:0];
//break out yes/no so we can set status
//NSString *strYesNO = [strPreParsed substringToIndex:2];
NSString *strYesOrNo = [strPreParsed substringWithRange: NSMakeRange(1, 1)];
//save approval for later
strApproval = strYesOrNo;
//debug
NSLog(#"strNo= %#",strYesOrNo);
NSLog(#"strPreParsed= %#", strPreParsed);
if([strYesOrNo compare:#"Y"] == NSOrderedSame)
{
lblStatus.text = #"Approved";
lblStatus.textColor = [UIColor greenColor];
}
if([strYesOrNo compare:#"N"] == NSOrderedSame)
{
lblStatus.text = #"Declined";
lblStatus.textColor = [UIColor redColor];
}
if([strYesOrNo compare:#"U"] == NSOrderedSame)
{
lblStatus.text = #"Try Again";
lblStatus.textColor = [UIColor redColor];
}
//set card type
if([lblCardNumber.text compare:#"4"] == NSOrderedSame)
{
lblCardType.text = #"Visa";
}
if([lblCardNumber.text compare:#"5"] == NSOrderedSame)
{
lblCardType.text = #"Master";
}
if([lblCardNumber.text compare:#"6"] == NSOrderedSame)
{
lblCardType.text = #"Discover";
}
//set cardnumber
lblCardNumber.text = strCardNumber;
//set expires
lblExpires.text = strExpires;
//set amount
lblAmount.text = strAmount;
//set approval string
lblApproval.text = strPreParsed;
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
//show signature
sigCaptureViewController *yetAnotherViewController = [[sigCaptureViewController alloc] initWithNibName:#"sigCaptureView" bundle:nil];
[self.navigationController pushViewController:yetAnotherViewController animated:YES];
[yetAnotherViewController release];
}
- (void)dealloc {
[super dealloc];
[lblCardType dealloc];
[lblCardNumber dealloc];
[lblExpires dealloc];
[lblAmount dealloc];
[lblApproval dealloc];
[lblStatus dealloc];
[strConfirmation dealloc];
[strCardNumber dealloc];
[strExpires dealloc];
[strAmount dealloc];
[strApproval dealloc];
}
#end
You are most likely releasing something twice in your SalesViewController, it's crashing when that object's dealloc is getting called and doing the 2nd release.
You didn't include that contorller's code, either look for it yourself or paste it here and I'll help you spot it :)
Here's a scenario you should look for:
// somewhere within your sales controller
- (void)someWhere {
NSArray *arr = [NSArray array];
self.myArray = arr;
[arr release]; // notice how arr wasn't initialized with an init
// so no release is required
// but since your myArray is a #property(retain) it won't crash here
// because the property did a retain
}
- (void)dealloc {
[myArray relase]; // this does the 2nd release and BOOM
}
EDIT after your target view controller was pasted:
It might be because you forgot to set one of the properties you're releasing in the dealloc. Try setting a breakpoints in your dealloc and see if one of the properties is actually null before releasing it, if so, that's why it crashes.
EDIT #2, are you sure you want to be calling [lblSometing dealloc] instead of [lblSomething release]?