2012-01-31 45 views
0

我從evernote網站下載了Iphone sdk.i的evernote示例應用程序,並將其與我的應用程序集成,我可以將說明保存到evernote並導入回來,但唯一的問題是登錄表單missing.the用戶名和密碼是靜態存儲在示例應用程序中。我不知道如何對此進行身份驗證以進行動態驗證。它使用單一設計。 in.h中ios登錄表格

extern NSString * const username; 
extern NSString * const password; 

@interface evernoteloginpage : UIViewController { 

.M

NSString * const username = @"nips55"; 
NSString * const password = @"annyan555"; 
@implementation evernoteloginpage 

,但我需要它動態的,我有兩個textfiled和登錄按鈕,我需要的textfiled值添加到用戶名和password.i嘗試了很多但沒有運氣。如果有人知道如何爲Evernote添加登錄表單,請幫助我。 在此先感謝。 編輯 現在我成功登錄這個代碼的幫助,但問題是如果登錄成功,它將重定向到下一頁,如代碼所示,如​​果用戶輸入錯誤的用戶名或密碼,它的應用程序崩潰。如何處理這段代碼中的錯誤信息。

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

} 

回答