NSUserDefault doesn't works - iphone

i am developing an app which has a evernote integration,everything works perfect but my problem is ,if i login with my account and uplode or downlode note to my aPP,then i logout from the evernote and login as a another user,it stills downlod and uplode note to previous account,,but login is sucess.
i put NsuserDefault for username and password textfileds and syncoronize it and pass it in evernote singlton shared class.my login looks like this
-(IBAction)_clickevernotelogin:(id)sender
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Keep this key private
NSString *consumerKey = [[[NSString alloc]
initWithString: #"myapp" ] autorelease];
[[NSUserDefaults standardUserDefaults] setObject:consumerKey forKey:#"consumerkeyevrnote"];
NSString *consumerSecret = [[[NSString alloc]
initWithString: #"agft5623636"] autorelease];
NSURL *userStoreUri = [[[NSURL alloc]
initWithString: #"https://www.evernote.com/edam/user"] autorelease];
NSString *noteStoreUriBase = [[[NSString alloc]
initWithString: #"https://www.evernote.com/edam/note/"] autorelease];
// These are for test purposes. At some point the user will provide his/her own.
NSString *username = [[[NSString alloc]
initWithString: _txtevernoteUsername.text] autorelease];
NSString *password = [[[NSString alloc]
initWithString: _txtevernotepasswrd.text] autorelease];
[[NSUserDefaults standardUserDefaults] setObject:_txtevernoteUsername.text forKey:#"usernameever"];
[[NSUserDefaults standardUserDefaults] setObject:_txtevernotepasswrd.text forKey:#"passwrdevernote"];
[[NSUserDefaults standardUserDefaults]synchronize];
THTTPClient *userStoreHttpClient = [[[THTTPClient alloc]
initWithURL:userStoreUri] autorelease];
TBinaryProtocol *userStoreProtocol = [[[TBinaryProtocol alloc]
initWithTransport:userStoreHttpClient] autorelease];
EDAMUserStoreClient *userStore = [[[EDAMUserStoreClient alloc]
initWithProtocol:userStoreProtocol] autorelease];
EDAMNotebook* defaultNotebook = NULL;
BOOL versionOk = [userStore checkVersion:#"Cocoa EDAMTest" :
[EDAMUserStoreConstants EDAM_VERSION_MAJOR] :
[EDAMUserStoreConstants EDAM_VERSION_MINOR]];
if (versionOk == YES)
{
#try {
NSError *error = nil;
NSString *unameever = _txtevernoteUsername.text;
NSString *pwdever = _txtevernotepasswrd.text;
[[NSUserDefaults standardUserDefaults] setObject:unameever forKey:#"usernameever"];
BOOL flag = [SFHFKeychainUtils storeUsername:unameever andPassword:pwdever forServiceName:#"mybibleappever" updateExisting:TRUE error:&error];
EDAMAuthenticationResult* authResult =
[userStore authenticate:username :password
:consumerKey :consumerSecret];
EDAMUser *user = [authResult user];
NSString *authToken = [authResult authenticationToken];
NSLog(#"Authentication was successful for: %#", [user username]);
NSLog(#"Authentication token: %#", authToken);
[[NSUserDefaults standardUserDefaults] setObject:authToken forKey:#"usernameevernotetocken"];
[[NSUserDefaults standardUserDefaults] setObject:[user username] forKey:#"usernameevernoteshow"];
NSURL *noteStoreUri = [[[NSURL alloc]
initWithString:[NSString stringWithFormat:#"%#%#",
noteStoreUriBase, [user shardId]] ]autorelease];
}
#catch (EDAMUserException * e) {
NSString * errorMessage = [NSString stringWithFormat:#"Please enter valid username & password", [e errorCode]];
UIAlertView *alertDone = [[UIAlertView alloc] initWithTitle: #"Evernote" message: errorMessage delegate: self cancelButtonTitle: #"Ok" otherButtonTitles: nil];
_acteverloginimage.hidden = YES;
_acteverlogin.hidden =YES;
[alertDone show];
[alertDone release];
return;
}
[pool drain];
}
my logout looks like this
[_btnusernameshow setTitle:nil forState:UIControlStateNormal];
NSError *error = nil;
NSString *usernameever = [[NSUserDefaults standardUserDefaults] objectForKey:#"usernameever"];
BOOL flag = [SFHFKeychainUtils deleteItemForUsername:usernameever andServiceName:#"mybibleappever" error:&error];
[[NSUserDefaults standardUserDefaults ]removeObjectForKey:#"usernameevernote"];
[[NSUserDefaults standardUserDefaults ]removeObjectForKey:#"passwrdevernote"];
[[NSUserDefaults standardUserDefaults ]removeObjectForKey:#"usernameevernotetocken"];
[[NSUserDefaults standardUserDefaults ]removeObjectForKey:#"usernameever"];
my evernote singlton class which share the instance look like this
here i am passing the nsuerdefault value to change the authentication information to this class
- (void) connect {
if (authToken == nil)
{
// In the case we are not connected we don't have an authToken
// Instantiate the Thrift objects
NSURL * NSURLuserStoreUri = [[[NSURL alloc] initWithString: userStoreUri] autorelease];
THTTPClient *userStoreHttpClient = [[[THTTPClient alloc] initWithURL: NSURLuserStoreUri] autorelease];
TBinaryProtocol *userStoreProtocol = [[[TBinaryProtocol alloc] initWithTransport:userStoreHttpClient] autorelease];
EDAMUserStoreClient *userStore = [[[EDAMUserStoreClient alloc] initWithProtocol:userStoreProtocol] autorelease];
// Check that we can talk to the server
bool versionOk = [userStore checkVersion: applicationName :[EDAMUserStoreConstants EDAM_VERSION_MAJOR] : [EDAMUserStoreConstants EDAM_VERSION_MINOR]];
if (!versionOk) {
// Alerting the user that the note was created
UIAlertView *alertDone = [[UIAlertView alloc] initWithTitle: #"Evernote" message: #"Incompatible EDAM client protocol version" delegate: self cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[alertDone show];
[alertDone release];
return;
}
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(evrloginnotif:) name:#"evrloginnotiff" object:nil];
//Checks if there is a saved User Name
NSError *error = nil;
if([defaults objectForKey:#"usernameever"]&&[defaults objectForKey:#"passwrdevernote"])
{
username = [defaults objectForKey:#"usernameever"];
password = [defaults objectForKey:#"passwrdevernote"];
//BOOL flag = [SFHFKeychainUtils storeUsername:username andPassword:password forServiceName:#"mybibleappever" updateExisting:TRUE error:&error];
// Returned result from the Evernote servers after authentication
EDAMAuthenticationResult* authResult =[userStore authenticate:username :password : consumerKey :consumerSecret];
// User object describing the account
self.user = [authResult user];
// We are going to save the authentication token
self.authToken = [authResult authenticationToken];
// and the shard id
self.shardId = [user shardId];
// Creating the user's noteStore's URL
noteStoreUri = [[[NSURL alloc] initWithString:[NSString stringWithFormat:#"%#%#", noteStoreUriBase, shardId] ] autorelease];
// Creating the User-Agent
UIDevice *device = [UIDevice currentDevice];
NSString * userAgent = [NSString stringWithFormat:#"%#/%#;%#(%#)/%#", applicationName,applicationVersion, [device systemName], [device model], [device systemVersion]];
// Initializing the NoteStore client
THTTPClient *noteStoreHttpClient = [[[THTTPClient alloc] initWithURL:noteStoreUri userAgent: userAgent timeout:15000] autorelease];
TBinaryProtocol *noteStoreProtocol = [[[TBinaryProtocol alloc] initWithTransport:noteStoreHttpClient] autorelease];
noteStore = [[[EDAMNoteStoreClient alloc] initWithProtocol:noteStoreProtocol] retain];
}
}
}
how to solve this bug,,thanks
EDIT
but when i rebuild the app,i am getting the correct notes from the username

NSUserDefaults *Test = [NSUserDefaults standardUserDefaults];
[Test removeObjectForKey:#"usernameevernote"];
[Test removeObjectForKey:#"passwrdevernote"];
[Test removeObjectForKey:#"usernameevernotetocken"];
[Test removeObjectForKey:#"usernameever"];
[Test synchronize];
maybe you should have remove objects and synchronize it again so it will remove all objects.

Add "[[NSUserDefaults standardUserDefaults] synchronize];" line everywhere you set value or remove key from NSUserDefault.
May be synchronization is the problem.

Related

Attach image to message composer in ios 6

How to attach an image to native message composer in ios6? I want to implement the same sharing via message function we can see in default photos app.
Thanks
For Mail:
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
NSData *exportData = UIImageJPEGRepresentation(pic ,1.0);
[mailController addAttachmentData:exportData mimeType:#"image/jpeg" fileName:#"Photo.jpeg"];
[self presentModalViewController:mailController animated:YES];
The only way is through email currently. Unless you want to create a own MMS gateway to allow your app to support MMS..
For Message:
After reading up, instead of using MFMessageComposeViewController,you could UIApplication sharedApplication.
Example:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.persistent = YES;
NSData *data = UIImageJPEGRepresentation(pic ,1.0);
pasteboard.image = [UIImage imageWithData:data];
NSString *phoneToCall = #"sms: 123-456-7890";
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded];
[[UIApplication sharedApplication] openURL:url];
Longpress and click on Paste and message will be pasted...
Hope this helps... pic refers to the UIImage you are passing...
{
NSMutableDictionary * attachment = [[NSMutableDictionary alloc]init];
[attachment setObject: UIImageJPEGRepresentation(imageView.image,0.5) forKey:#"attachmentData"];
[attachment setObject: #"productImage.jpeg" forKey:#"attachmentFileName"];
[attachment setObject: #"jpeg" forKey:#"attachmentFileMimeType"];
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject: #"subject" forKey:#"subject"];
[params setObject: #"matterText" forKey:#"matterText"];
[params setObject: [[NSMutableArray alloc]initWithObjects:attachment, nil] forKey:#"attachments"];
}
#pragma mark - Sharing Via Email Related Methods
-(void)emailInfo:(NSMutableDictionary*)info
{
if (![MFMailComposeViewController canSendMail])
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Email Configuration"
message:#"We cannot send an email right now because your device's email account is not configured. Please configure an email account from your device's Settings, and try again."
delegate:nil
cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
return;
}
MFMailComposeViewController *emailer = [[MFMailComposeViewController alloc] init];
emailer.mailComposeDelegate = self;
NSString * subject = [info objectForKey:#"subject"];
NSString * matterText = [info objectForKey:#"matterText"];
if(subject)
[emailer setSubject:subject];
if(matterText)
[emailer setMessageBody:matterText isHTML:NO];
NSMutableArray * attachments = [info objectForKey:#"attachments"];
if (attachments)
{
for (int i = 0 ; i < attachments.count ; i++)
{
NSMutableDictionary * attachment = [attachments objectAtIndex:i];
NSData * attachmentData = [attachment objectForKey:#"attachmentData"];
NSString * attachmentFileName = [attachment objectForKey:#"attachmentFileName"];
NSString * attachmentFileMimeType = [attachment objectForKey:#"attachmentFileMimeType"];
[emailer addAttachmentData:attachmentData mimeType:attachmentFileMimeType fileName:attachmentFileName];
}
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
emailer.modalPresentationStyle = UIModalPresentationPageSheet;
}
[self.navigationController.topViewController presentViewController:emailer animated:YES completion:nil];
}
I think you cant attach an image in the message composer. It is only possible in mail composer.

Save the username & password after login for the first time and not to ask again

I am developing one ios app, in that I need to enter company-code and accesscode to login. After login for the first time with the access code, We cannot prefer to ask for accesscode again when we open the application. I mean I need to save the preferences.
And my code is here
- (IBAction)loginClicked:(id)sender {
#try {
if([[txtsecurecode text] isEqualToString:#""] || [[OrganizationCode text] isEqualToString:#""] ) {
[self alertStatus:#"Please enter Access code" :#"Login Failed!":0];
} else {
NSString *post =[[NSString alloc] initWithFormat:#"txtsecurecode=%# #&password=%#",[txtsecurecode text],[OrganizationCode text]];
NSLog(#"PostData: %#",post);
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://mycompany.com/AccountService/security/ValidateAccess?accesscode=%#&companycode=%#&type=1", txtsecurecode.text, OrganizationCode.text]];
[[ NSUserDefaults standardUserDefaults] setValue:OrganizationCode forKey:#"OrganizationCode"];
[[ NSUserDefaults standardUserDefaults] setValue:txtsecurecode forKey:#"txtsecurecode"];
[[NSUserDefaults standardUserDefaults] synchronize];
txtsecurecode = [[NSUserDefaults standardUserDefaults] objectForKey:#"txtsecurecode"];
OrganizationCode = [[NSUserDefaults standardUserDefaults] objectForKey:#"OrganizationCode"];
// NSString *num = [[NSUserDefaults standardUserDefaults] stringForKey:#"txtsecurecode"];
NSString *responseData = [[NSString alloc]initWithData:[NSData dataWithContentsOfURL:url] encoding:NSUTF8StringEncoding];
if([responseData isEqualToString:#""]){
[self alertStatus:#"Please enter valid Access Code" :#"Login Failed !" :0];
}
else
{
responseData = [responseData stringByReplacingOccurrencesOfString:#" "" " withString:#""];
responseData = [responseData stringByReplacingOccurrencesOfString:#"\\" withString:#""];
NSString* encodedString = [responseData stringByReplacingPercentEscapesUsingEncoding:
NSUTF8StringEncoding];
NSLog(#"Response ==> %#" ,encodedString);
UIWebView *webView;
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, 320, 470)];
webView.backgroundColor = [UIColor clearColor];
webView.opaque = NO;
[webView setDelegate:self];
NSString* urlTwo = [[encodedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
stringByReplacingOccurrencesOfString:#"%22" withString:#""];
NSURL *url2;
if([urlTwo hasPrefix:#"http://"]){
url2 = [NSURL URLWithString:urlTwo];
}else{
url2 = [NSURL URLWithString:[NSString stringWithFormat:#"http://%#" , urlTwo]];
}
NSLog(#"url2:%#", url2);
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url2];
[webView loadRequest:requestObj];
[[self view] addSubview:webView];
}
}
}
#catch (NSException * e) {
NSLog(#"Exception: %#", e);
[self alertStatus:#"Login Failed." :#"Login Failed!" :0];
}
}
I had used NSUserDefaults method to save the login credentials but it is not working. Credentials are not saving, again the app is asking for credentials.
try this
when you successfull login then save it in NSUserDefaults
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
[status setObject:#"1" forKey:#"Login"];
Next time only check
NSUserDefaults *objUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *strSuccess=[objUserDefaults objectForKey:#"Login"];
if ([strSuccess isEqualToString:#"1"]) {
// just push the next view.
}
else {
// open login screen
}
OR Next option, if you care about security, the keychain.
Edit
.h file
NSUserDefaults *objUserDefaults;
#property (nonatomic,retain) NSUserDefaults *objUserDefaults;
.m file
#synthesize objUserDefaults;
Where you first time login Method write this on response\
objUserDefaults = [NSUserDefaults standardUserDefaults]
[objUserDefaults setObject:#"1" forKey:#"Login"];
and when you required for login check then
NSString *strSuccess=[objUserDefaults objectForKey:#"Login"];
if ([strSuccess isEqualToString:#"1"]) {
// just push the next view.
}
else {
// open login screen
}
OrganizationCode is not a string, and you are getting it as a string with this:
OrganizationCode = [[NSUserDefaults standardUserDefaults] stringForKey:#"OrganizationCode"];
You need to use objectForKey: instead, try with that:
OrganizationCode = [[NSUserDefaults standardUserDefaults] objectForKey:#"OrganizationCode"];
And another thing, OrganizationCode seems like the name of a class, not an instance of an object, are you sure you are using it in the right way?
To Store: Login Button:
-(IBAction)Login:(id)sender
{
if (success) {
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
[status setObject:#"LOGGING" forKey:#"STATUS"];
// GO TO NEXT FUNCTION ??
}
}
To Get:Validation Button:
-(void)load_view
{
NSUserDefaults *status=[NSUserDefaults standardUserDefaults];
NSString *status_str=[status objectForKey:#"STATUS"];
if ([status_str isEqualToString:#"LOGGING"]) {
// GO TO NEXT SUCCESS FUNCTION
}
else
{
// GO TO Login View
}
}

Login form for Evernote in ios

i downloaed the evernote sample app from the evernote site for Iphone sdk.i integrated it with my application,i can save note to evernote and import back ,but the only problem is login form missing.the username and password is stored statically in the sample app.i dont know how to authenticate this to dynamically.it is using singlton desing.
in.h
extern NSString * const username;
extern NSString * const password;
#interface evernoteloginpage : UIViewController {
.m
NSString * const username = #"nips55";
NSString * const password = #"annyan555";
#implementation evernoteloginpage
but i need it dynamically,i have two textfiled and a login button i need to add the textfiled values to username and password.i tried a lot but no luck.if anyone knows how to add a loginform for evernote ,please help me.
thanks in advance.
EDIT
now i sucessfully login with the help of this code,but again ther problem is if the login is sucess it will redirect to next page as shown in the code,if the user enter the wrong username or password,ithe app crashes.how to handele the rror mamangement in this code.
-(IBAction)_clickevernotelogin:(id)sender
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Keep this key private
NSString *consumerKey = [[[NSString alloc]
initWithString: #"app" ] autorelease];
[[NSUserDefaults standardUserDefaults] setObject:consumerKey forKey:#"consumerkeyevrnote"];
NSString *consumerSecret = [[[NSString alloc]
initWithString: #"12345678"] autorelease];
// For testing we use the sandbox server.
NSURL *userStoreUri = [[[NSURL alloc]
initWithString: #"https://www.evernote.com/edam/user"] autorelease];
NSString *noteStoreUriBase = [[[NSString alloc]
initWithString: #"https://www.evernote.com/edam/note/"] autorelease];
// These are for test purposes. At some point the user will provide his/her own.
NSString *username = [[[NSString alloc]
initWithString: _txtevernoteUsername.text] autorelease];
NSString *password = [[[NSString alloc]
initWithString: _txtevernotepasswrd.text] autorelease];
[[NSUserDefaults standardUserDefaults] setObject:_txtevernoteUsername.text forKey:#"usernameevernote"];
[[NSUserDefaults standardUserDefaults] setObject:_txtevernotepasswrd.text forKey:#"passwrdevernote"];
THTTPClient *userStoreHttpClient = [[[THTTPClient alloc]
initWithURL:userStoreUri] autorelease];
TBinaryProtocol *userStoreProtocol = [[[TBinaryProtocol alloc]
initWithTransport:userStoreHttpClient] autorelease];
EDAMUserStoreClient *userStore = [[[EDAMUserStoreClient alloc]
initWithProtocol:userStoreProtocol] autorelease];
EDAMNotebook* defaultNotebook = NULL;
BOOL versionOk = [userStore checkVersion:#"Cocoa EDAMTest" :
[EDAMUserStoreConstants EDAM_VERSION_MAJOR] :
[EDAMUserStoreConstants EDAM_VERSION_MINOR]];
if (versionOk == YES)
{
EDAMAuthenticationResult* authResult =
[userStore authenticate:username :password
:consumerKey :consumerSecret];
EDAMUser *user = [authResult user];
NSString *authToken = [authResult authenticationToken];
NSLog(#"Authentication was successful for: %#", [user username]);
NSLog(#"Authentication token: %#", authToken);
NSURL *noteStoreUri = [[[NSURL alloc]
initWithString:[NSString stringWithFormat:#"%#%#",
noteStoreUriBase, [user shardId]] ]autorelease];
[pool drain];
// this is next page if the login sucess
evernotemainpage *detailViewController = [[evernotemainpage alloc] initWithNibName:#"evernotemainpage" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
}
Unfortunately, the Eevernote API currently does not contain any code samples for iOS. If you need information or an example on how to do this check out this article.
http://digitalpericope.net/?p=27

problem submitting tweet to twitter from iphone

MGTwitterEngine.m
- (NSString *)username
{
return [[_username retain] autorelease];
}
- (NSString *)password
{
return [[_password retain] autorelease];
}
- (void)setUsername:(NSString *)newUsername password:(NSString *)newPassword
{
// Set new credentials.
[_username release];
_username = [newUsername retain];
[_password release];
_password = [newPassword retain];
if ([self clearsCookies]) {
// Remove all cookies for twitter, to ensure next connection uses new credentials.
NSString *urlString = [NSString stringWithFormat:#"%#://%#",
(_secureConnection) ? #"https" : #"http",
_APIDomain];
NSURL *url = [NSURL URLWithString:urlString];
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSEnumerator *enumerator = [[cookieStorage cookiesForURL:url] objectEnumerator];
NSHTTPCookie *cookie = nil;
while (cookie == [enumerator nextObject]) {
[cookieStorage deleteCookie:cookie];
}
}
}
- (NSString *)sendUpdate:(NSString *)status
{
return [self sendUpdate:status inReplyTo:0];
}
- (NSString *)sendUpdate:(NSString *)status inReplyTo:(unsigned long)updateID
{
if (!status) {
return nil;
}
NSString *path = [NSString stringWithFormat:#"statuses/update.%#", API_FORMAT];
NSString *trimmedText = status;
if ([trimmedText length] > MAX_MESSAGE_LENGTH) {
trimmedText = [trimmedText substringToIndex:MAX_MESSAGE_LENGTH];
}
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:0];
[params setObject:trimmedText forKey:#"status"];
if (updateID > 0) {
[params setObject:[NSString stringWithFormat:#"%u", updateID] forKey:#"in_reply_to_status_id"];
}
NSString *body = [self _queryStringWithBase:nil parameters:params prefixed:NO];
return [self _sendRequestWithMethod:HTTP_POST_METHOD path:path
queryParameters:params body:body
requestType:MGTwitterUpdateSendRequest
responseType:MGTwitterStatus];
}
TwitterPostViewController.m
- (IBAction)submitTweet{
[tweet resignFirstResponder];
if([[tweet text] length] > 0){
NSLog(#"%#",[[NSUserDefaults standardUserDefaults] valueForKey:#"TwitterUsername"]);
NSLog(#"%#",[[NSUserDefaults standardUserDefaults] valueForKey:#"TwitterPassword"]);
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[engine sendUpdate:[tweet text]];
}
}
- (void)requestFailed:(NSString *)requestIdentifier withError:(NSError *)error{
NSLog(#"Fail: %#", error);
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
UIAlertView *failAlert;
if([error code] == 401){
failAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Incorrect Username & Password." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[failAlert setTag:10];
[failAlert setDelegate:self];
}
else
{
failAlert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Failed sending status to Twitter." delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
}
[failAlert show];
[failAlert release];
}
It shows me the fail popup of Incorrect username and password
I have checked through nslog that username and password are going correct.
what could be wrong?
It looks like the version of MGTwitterEngine you're using is trying to use basic auth. That was switched off in Twitter in favour of OAuth. Get a newer version of MGTwitterEngine (or a fork that supports OAuth).

How to show/hide UIImageView when I want

I'm having a little problem with an iPhone app I'm currently developing.
When the user touch a button, it calls an IBAction named refreshQuestion, which is supposed to show an image hover the screen to ask the user to wait a moment, then it has to call another function, and finally it has to hide the image.
The problem is that the image won't appear. As well as the network activity indicator.
Any help?
Here is the code :
- (IBAction)refreshQuestion:(id)sender{
pleaseWait.hidden = NO;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[self loadData];
pleaseWait.hidden = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
EDIT :
Here is my LoadData function :
- (void)loadData{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString * idUtilisateur = [userDefaults objectForKey:#"idUtilisateur"];
NSString * stringUrlQuestion = [NSString stringWithFormat:#"http://www.mywebsiteURL"];
NSURL * urlQuestion = [NSURL URLWithString:stringUrlQuestion];
QuestionParser * parser = [[QuestionParser alloc] init];
[parser parseXMLAtURL:urlQuestion parseError:nil] ;
int nbQuestions = [parser.arrayOfQuestion count];
[parser release];
NSFetchRequest *requete = [[NSFetchRequest alloc] init];
NSEntityDescription *entite = [NSEntityDescription entityForName:#"Question" inManagedObjectContext:self.managedObjectContext];
[requete setEntity:entite];
NSSortDescriptor * sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"idQuestion" ascending:YES];
NSArray * sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[requete setSortDescriptors:sortDescriptors];
[sortDescriptor release];
[sortDescriptors release];
NSError * error;
NSMutableArray *mutableFetchResult = [[self.managedObjectContext executeFetchRequest:requete error:&error] mutableCopy];
[requete release];
if(mutableFetchResult == nil){
NSLog(#"Erreur viewWillAppear : %#", error);
}
questionDuJour = [mutableFetchResult objectAtIndex:0];
if (nbQuestions == 0){
UIAlertView* alertViewConnection = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Error while retreiving data" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertViewConnection show];
[alertViewConnection release];
}
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:#"EEEE d MMMM"];
NSLocale * localisation = [[[NSLocale alloc] initWithLocaleIdentifier:#"fr_FR"] autorelease];
[outputFormatter setLocale:localisation];
labelJour.text = [NSString stringWithFormat:#"%#",[outputFormatter stringFromDate:questionDuJour.dateQuestion]];
textQuestion.text = questionDuJour.textQuestion;
citation.text = [NSString stringWithFormat:#"%#",questionDuJour.citation];
labelAuteur.text = [NSString stringWithFormat:#"%#",questionDuJour.auteur];
[outputFormatter release];
NSLog(#"stop animating");
}
I think your code [self loadData] executes in microseconds.
Check by using this code alone,
pleaseWait.hidden = NO;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
EDIT:
Check this, if you still get the same problem check whether you have assigned IBoutlet or not. Because what you are doing is the correct way.
Sounds like everything is executing on the UI Thread. Post your loadData method so we can see what its doing. Chances are you have to convert this method to use one of the asynchronous techniques which will return immediately and allow the UI thread to continue. You can then detect when its done loading the data and change the visibility of the image again.