Data Not inserted In Sqlite objective c - ios

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

Related

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 to reveal all string padding from txt file in Xcode?

I making a word game so Ive set all the word in a .txt file, and i've added a show 1st letter button:
Code:
if ([buttonTitle isEqualToString:#"reveal"]) {
UIAlertView *alertuser;
NSString *prla = [NSString stringWithFormat:#"%#", [lst_word objectAtIndex:nCurrentWord]];
NSString *finished = [[prla substringToIndex:1] stringByPaddingToLength:prla.length withString: #"_" startingAtIndex:0];
alertuser = [[UIAlertView alloc]initWithTitle:#"This is the first letter:" message:finish delegate:self cancelButtonTitle:#"Thanks" otherButtonTitles:nil, nil];
[alerta show];
How would I make it show and reveal all the letters from the word in the .txt file?
NSString *finishText = [[prlt substringToIndex:1] stringByPaddingToLength:prlt.length withString: #"_" startingAtIndex:0];
alerta = [[UIAlertView alloc]initWithTitle:#"First Letter is:" message:finishText delegate:self cancelButtonTitle:#"Thanks" otherButtonTitles:nil, nil];
[alerta show];
I need this reversed to allow the full answer from the txt file!
substringWithRange: may be the function you are looking for.
The sample code below will print word by word of a string
NSString *sampleString = #"abcedefgh";
for(int i = 0; i < [sampleString length]; i++)
{
NSLog(#"word = %#", [sampleString substringWithRange:NSMakeRange(i, 1)])
}
EDIT:
In place of
NSString *finishedText = [[prlt substringToIndex:1] stringByPaddingToLength:prlt.length withString: #"_" startingAtIndex:0];
use below code, this will solve your issue
NSString *finishedText= [prlt substringWithRange:NSMakeRange(0, prla.length)];

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

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