Fetching and comparing CFBundleVersion from plist - ios

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.

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];

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?

How to remove braces from an array in objective C? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
NSMutableArray*array = [[NSMutableArray alloc] initWithObjects:#"a", #"d", #"r", nil];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"msg"
message:[array Description]
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
Output should be like
a
d
r
Not like
(a
d
r
)
You can directly use NSString for this purpose.
But if you insist on using NSMutableArray then do something like this.
NSMutableArray *arr = [[NSMutableArray alloc] initWithObjects:#"a",#"b",#"c", nil];
NSString *joinedString = [arr componentsJoinedByString:#" "];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"msg"
message:joinedString
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
You are sending an NSArray description to an NSString parameter. This is where the braces come from. If you send a description message to an array, you will get back a string with all objects in an array enclosed with 'your' braces.
I am not sure what are you actually trying to achieve here. Message should be an NSString object like #"Invalid input".
If you want output a d r, I would combine objects of array into single string:
NSMutableArray*array = [[NSMutableArray alloc] initWithObjects:#"a", #"d", #"r", nil];
NSString *combinedString = [NSString stringWithFormat:#"%# %# %#", array[0], array[1], array[2]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"msg"
message:combinedString
delegate:nil
cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];

How to read seperate fields in a csv file and compare with user input?

I am building an app where use can upload a csv file that contains First Name, Last Name and email in 3 seperate columns. User interface will have 3 text fields and a button. When user enters the first name or last name or email, and click search button, the whole documenent must be searched and display an alert saying that the record was found in the file. This is the function that I am using, but it only reads the first row and first column. Please help
- (void) SearchStudent
{
NSArray *DocumentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *DocumentDirectory = [DocumentPath objectAtIndex:0];
NSString *FullPath = [DocumentDirectory stringByAppendingPathComponent:[NSString stringWithFormat:#"example.csv"]];
NSString * pstrCSVFile= [NSString stringWithContentsOfFile:FullPath encoding:NSASCIIStringEncoding error:NULL];
NSArray * paRowsOfCSVFile= [pstrCSVFile componentsSeparatedByString:#"\n"];
NSArray *paColumnsOfRow;
NSString *pstrFirstColumn;
for(NSString * pstrRow in paRowsOfCSVFile)
{
paColumnsOfRow= [pstrRow componentsSeparatedByString:#","];
pstrFirstColumn= [paColumnsOfRow objectAtIndex:0];
if([pstrFirstColumn localizedCaseInsensitiveCompare:GWIDText.text] == NSOrderedSame)
{
UIAlertView *alertingFileName = [[UIAlertView alloc]initWithTitle:#"Error" message:#"Found" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alertingFileName show];
break;
}
else
{
UIAlertView *alertingFileName1 = [[UIAlertView alloc]initWithTitle:#"Error" message:#"Not Found" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alertingFileName1 show];
break;
}
}
}
It looks like your else statement is breaking out of the for loop if the first name doesn't match. You'll want to remove that and perhaps add a variable to track if you've found a match. Only set it if you match the name. After your for loop, check the variable to see if there was a match. If not, then show your UIAlertView for "Not Found".
Couple of hints:
You are checking for one column only.
if([pstrFirstColumn localizedCaseInsensitiveCompare:GWIDText.text] == NSOrderedSame)
Do the same with the other two columns. Then you will solve your first problem of only checking one column.
Looks like the line terminator is not correct. Depending on which platform the csv file was created, it might have different line terminator. I would suggest taking a text editor like notepad++ for instance and viewing hidden code to find out your line terminator. Then use the terminator to split rows. Make sure you are getting more than 1 row (just output the rows variable].

Game center submission not working

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];
}

Resources