Game center submission not working - ios

I have an app and am trying to submit scores to game center. this is my code:
- (IBAction) submitScore{
NSString *show = [[NSString alloc] initWithFormat:#"Note: Scores may take some time to update"];
self.note.text = show;
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Submitted"
message:#"Your score has been submitted to the Gamecenter leaderboard"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
array = [NSMutableArray arrayWithContentsOfFile:Path];
NSString *s = [[NSNumber numberWithInteger:[array count]] stringValue];
NSString *denom = [NSString stringWithFormat: #"%d", 15];;
double resultInNum;
double sdouble = [s doubleValue];
double denomdouble = [denom doubleValue];
resultInNum = sdouble/denomdouble * 100;
if(resultInNum > 0)
{
self.currentLeaderBoard = kLeaderboardID;
[self.gameCenterManager reportScore: resultInNum forCategory: self.currentLeaderBoard];
Submit.enabled = NO;
}
array = [NSMutableArray arrayWithContentsOfFile:Path];
[array writeToFile:Path atomically:YES];
NSLog(#"Count: %i", [array count]);
}
however when i try to do it it does not submit to the leader board. there are no errors that i am receiving in the debugger, and it used to work until i added more than one leader board. whats wrong here?

Score value must be an int64_t.
And I don't get why you are using NSStrings instead of directly assigning values?

Just make sure that you do the correct code for submitting the score. This is a way that I really like. Even though you will get warnings because they don't want you to use it in iOS 7, it still works. Just let me know if it doesn't work.
(IBAction)submitscoretogamecenter{
GKLocalPlayer *localplayer = [GKLocalPlayer localPlayer];
[localplayer authenticateWithCompletionHandler:^(NSError *error) {
}];
//This is the same category id you set in your itunes connect GameCenter LeaderBoard
GKScore *myScoreValue = [[[GKScore alloc] initWithCategory:#"insertCategory"] autorelease];
myScoreValue.value = scoreInt;
[myScoreValue reportScoreWithCompletionHandler:^(NSError *error){
//insert what happens after it's posted
}];
[self checkAchievements];
}

Related

Data Not inserted In Sqlite objective c

I want to insert some values in a table of database.but it is showing (NULL) on insertion
I am using This code
http://pastie.org/10929618
I have used this Link for Reference
http://www.tutorialspoint.com/ios/ios_sqlite_database.htm
//Insert Method
-(void)SaveAction{
BOOL success = NO;
NSString *alertString = #"Data Insertion failed";
success = [[DBManager getSharedInstance]saveData:#"100" username:#"byname" type:#"one2one" user_to:#"144" user_from:#"145" timestamp:#"42015"];
if (success == NO) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:
alertString message:nil
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
}
}
You are missing the column value.
// you are passing the value use below method but dnt have "message1" column value
success = [[DBManager getSharedInstance]saveData:#"100" username:#"byname" type:#"one2one" user_to:#"144" user_from:#"145" timestamp:#"42015"];
// compare the below query
NSString *insertSQL = [NSString stringWithFormat:#"insert into chatDetail (chat_id,username, type, message1,user_to,user_from,timestamp) values (\"%ld\",\"%#\", \"%#\", \"%#\",\"%#\",\"%#\")",(long)[chat_id integerValue], username, type, user_to,user_from,timestamp];

Fetching and comparing CFBundleVersion from plist

I'm trying to compare CFBundleVersion key of 2 Apps inside com.apple.mobile.installation.plist which include the info of every installed application on iPhone
NSString *appBundleID =#"net.someapp.app";
NSString *appBundleID2=#"net.someapp.app2";
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:
#"/var/mobile/Library/Caches/com.apple.mobile.installation.plist"];
NSDictionary *User = [dict valueForKey:#"User"];
//get first app version
NSDictionary *bundleID = [User valueForKey:appBundleID];
NSString *appVersion = [bundleID valueForKey:#"CFBundleVersion"];
//get second app version
NSDictionary *bundleID2 = [User valueForKey:appBundleID2];
NSString *appVer2 = [bundleID2 valueForKey:#"CFBundleVersion"];
[dict release];
if ([appVersion isEqualToString:appVer2]) {
NSString *str1=[NSString stringWithFormat:#"Original Version: %#",appVersion];
NSString *str2=[NSString stringWithFormat:#"2nd Version: %#",appVer2];
NSString *msg=[NSString stringWithFormat:#"%#\n%#",str1,str2];
UIAlertView* alertView = [[UIAlertView alloc]
initWithTitle:#"Same Versions!" message:msg delegate:nil
cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alertView show];
}
else {
NSString *str1=[NSString stringWithFormat:#"Original Version: %#",appVersion];
NSString *str2=[NSString stringWithFormat:#"2nd Version: %#",appVer2];
NSString *msg=[NSString stringWithFormat:#"%#\n%#",str1,str2];
UIAlertView* alertView = [[UIAlertView alloc]
initWithTitle:#"Different Versions!" message:msg delegate:nil
cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alertView show];
}
The version of both apps is currently set to 2.11.8
I am getting the following wrong result:
If i set the NSString manually:
NSString *appVersion =#"2.11.8";
NSString *appVer2 =#"2.11.8";
i get the correct desired result:
I also tried other ways to compare the strings but the result was always the same, so i guess the problem is with fetching the values of the keys?
Any help is appreciated
I am so used to ARC that I am not 100% sure about the MRC rules anymore. But I assume
that you either have to retain the values appVersion and appVer2 from the dictionary,
or alternatively, postpone the [dict release] until after the values are no longer needed.
Since you don't own the values fetched from the dictionary, they become invalid if the
dictionary is released.
(This would not be a problem if you compile with ARC!)
Remark: The designated method to get a value from a dictionary is objectForKey:.
valueForKey: works also in many cases, but can be different. It should only be used
for Key-Value Coding magic.

How can I find images link in RSS Feed

I am creating app which is based on RSS Feed. I am trying to parse image link. But I don't get the link. The code is as follows-
-(void) grabRSSFeed:(NSString *)blogAddress
{
// Autorelease pool for secondary threads
// NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Initialize the blogEntries MutableArray that we declared in the header
feedEntries = [[NSMutableArray alloc] init];
// Convert the supplied URL string into a usable URL object
NSURL *url = [NSURL URLWithString:blogAddress];
if(url==nil)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"RSS Feed" message:#"Please enter a valid RSS feed URL."
delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
}
else
{
// Create a new rssParser object based on the TouchXML "CXMLDocument" class, this is the
// object that actually grabs and processes the RSS data
NSError *error;
CXMLDocument *rssParser = [[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:&error];
if(rssParser==nil)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"RSS Feed" message:#"Please enter a valid RSS feed URL."
delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
}
else
{
// Create a new Array object to be used with the looping of the results from the rssParser
NSArray *resultNodes = NULL;
// Set the resultNodes Array to contain an object for every instance of an node in our RSS feed
resultNodes = [rssParser nodesForXPath:#"//item" error:nil];
// Loop through the resultNodes to access each items actual data
for (CXMLElement *resultElement in resultNodes) {
// Create a temporary MutableDictionary to store the items fields in, which will eventually end up in blogEntries
NSMutableDictionary *feedItem = [[NSMutableDictionary alloc] init];
// Create a counter variable as type "int"
int counter;
// Loop through the children of the current node
for(counter = 0; counter < [resultElement childCount]; counter++)
{
// Add each field to the blogItem Dictionary with the node name as key and node value as the value
if([[resultElement childAtIndex:counter] stringValue]!=nil)
[feedItem setObject:[[resultElement childAtIndex:counter] stringValue] forKey:[[resultElement childAtIndex:counter] name]];
}
// Add the blogItem to the global blogEntries Array so that the view can access it.
[feedEntries addObject:feedItem];
}
NSLog(#"Feeds = %#",feedEntries);
[feedEntries writeToFile:[[self applicationDocumentsDirectory] stringByAppendingPathComponent:#"Feeds.plist"] atomically:YES];
// [self performSelectorOnMainThread:#selector(reloadTableData:) withObject:nil waitUntilDone:NO];
}
}
}
How can I get image link about particular news?

Why is my array returning null?

I am calling getBoardingCards once here:
BRPBoardingCards *boardingCards = [[BRPBoardingCards alloc] init];
boardingCardsArray = [boardingCards getBoardingCards];
The array is returning null though (in the NSLog shown). What am I doing wrong?
- (NSArray*)getBoardingCards
{
NSMutableArray *storedArray = [[NSMutableArray alloc] init];
Utils *utils = [[Utils alloc] init];
NSUserDefaults *properties = [utils getUserDefaults];
// check if its the first time we are running the app.
if(![[properties objectForKey:#"first_run"] isEqualToString:#"no"]){
//I decided it is for american tourists and every booking office allows payment in dollars because I dont have a euros key on my keyboard.
//Car also has lots of seats. 1337 of them to be precise.
[self setNewBoardingCardWithCardType:#"car" WithPrice:#"$1.50" AndStartLocation:#"airport" AndEndLocation:#"restaurant" WithSeat:#"1337" andExtraInformation:#"We dont like you so we are giving you the back seat by yourself."];
[self setNewBoardingCardWithCardType:#"helicopter" WithPrice:#"$500" AndStartLocation:#"restaurant" AndEndLocation:#"hospital" WithSeat:#"1" andExtraInformation:#"You are driving."];
[self setNewBoardingCardWithCardType:#"train" WithPrice:#"$100" AndStartLocation:#"restaurant" AndEndLocation:#"ditch" WithSeat:#"STANDONHEAD" andExtraInformation:#"No Seats on this train. Gotta stand on your head. Dont forget your white lightning for the ditch."];
[self setNewBoardingCardWithCardType:#"Fire Engine" WithPrice:#"$10" AndStartLocation:#"restaurant" AndEndLocation:#"burning house" WithSeat:#"HOSE" andExtraInformation:#"Take the hose to put out this fire we are heading to. "];
[self setNewBoardingCardWithCardType:#"Nimbus" WithPrice:#"$300" AndStartLocation:#"burning house" AndEndLocation:#"popo floating island" WithSeat:#"LEVITATION" andExtraInformation:#"Dont forget to turn super saiyan on your way up there. "];
[self setNewBoardingCardWithCardType:#"Sky Dive" WithPrice:#"$1020" AndStartLocation:#"popo floating island" AndEndLocation:#"home" WithSeat:#"GRAVITY" andExtraInformation:#"Ohh! that Adrenalines pumping. "];
[self setNewBoardingCardWithCardType:#"Legs" WithPrice:#"$50" AndStartLocation:#"ditch" AndEndLocation:#"park bench hotel" WithSeat:#"VODKA" andExtraInformation:#"Time to get a good nights rest and sobre up. "];
[self setNewBoardingCardWithCardType:#"Bicycle" WithPrice:#"$5" AndStartLocation:#"park bench hotel" AndEndLocation:#"home" WithSeat:#"BIKESEAT1" andExtraInformation:#"What a terrible hangover. Time to head home. "];
[self setNewBoardingCardWithCardType:#"ambulance" WithPrice:#"$40" AndStartLocation:#"hospital" AndEndLocation:#"home" WithSeat:#"LEVITATION" andExtraInformation:#"Well that was a bad idea! "];
[properties setObject:#"no" forKey:#"first_run"];
[properties synchronize];
NSLog(#"did set first run to no");
}
storedArray = [[properties objectForKey:#"cards"] mutableCopy];
NSLog(#"getBoardingCards storedArray: %#", storedArray);
return storedArray;
}
- (NSArray*)getBoardingCardsByType:(NSString*)cardType
{
// at this point i would create a for loop and iterate through the array checking if (type isEqualToString:cardType).
// But this is just an idea for later. To go by only a certain type of route.
return nil;
}
- (void)setNewBoardingCardWithCardType:(NSString*)cardType WithPrice:(NSString*)price AndStartLocation:(NSString*)startLocation AndEndLocation:(NSString*)endLocation WithSeat:(NSString*)seatCode andExtraInformation:(NSString*)extraInfo{
// populate the dictionary with data.
NSMutableDictionary *card = [[NSMutableDictionary alloc] init];
[card setObject:cardType forKey:#"type"];
[card setObject:price forKey:#"price"];
[card setObject:startLocation forKey:#"startLocation"];
[card setObject:endLocation forKey:#"endLocation"];
[card setObject:seatCode forKey:#"seat"];
[card setObject:extraInfo forKey:#"info"];
// get our stored array.
Utils *utils = [[Utils alloc] init];
NSUserDefaults *properties = [utils getUserDefaults];
NSMutableArray *storedArray = [[properties objectForKey:#"cards"] mutableCopy];
[storedArray addObject:card];
// set the stored array.
[properties setObject:storedArray forKey:#"cards"];
[properties synchronize];
}
You're not creating the cards mutable array in the NSUserDefaults.
This line (in setNewBoardingCardWithCardType:):
NSMutableArray *storedArray = [[properties objectForKey:#"cards"] mutableCopy];
is essentially
NSMutableArray *storedArray = [nil mutableCopy];
which is the same as
NSMutableArray *storedArray = nil;
Check if the object for this key exist, if not - create it and then use it.

Error when assigning NSString variable in a block

- (NSString *) geocodeAddressFromCoordinate:(CLLocationCoordinate2D)coordinate
{
CLLocation *location = [[CLLocation alloc]initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
__block NSMutableString * address = [NSMutableString string];
geocoder = [[CLGeocoder alloc]init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error)
{
if (error) {
NSLog(#"%#", [error localizedDescription]);
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"No results were found" message:#"Try another search" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil, nil];
alert.show;
return;
}
if ([placemarks count]>0)
{
NSLog([placemarks description]);
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(placemark.locality);
//This line makes an error
[address initWithString:placemark.locality];**
}
}];
return address;
}
Got following runtime error:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* initialization method
-initWithCharactersNoCopy:length:freeWhenDone: cannot be sent to an abstract object of class __NSCFString: Create a concrete instance!'
You should never call 'initWithString:' without a matching alloc. Looks more like what you want is [address setString:placemark.locality]
You have already initialized address with this line [NSMutableString string]; so your call to [address initWithString:placemark.locality]; is trying to initialize an already initialized object.
Change this:
[address initWithString:placemark.locality];
To:
[address setString:placemark.locality];
NSString Class Reference
NSMutableString Class Reference
[address initWithString:placemark.locality];
should be something more like:
address = placemark.locality;
or
[address appendString:placemark.locality];
depending on what yu are trying to accomplish.
At this point, your string is already initialized, [NSMutableString string] is a convenience method which essential returns [[[NSMutableString alloc] init] autorelease]. You are trying to re init an already inited object, which is bad.
Change that line to [address appendString:placemark.locality];

Resources