0
我正在使用MGTwitterEngine + Oauth庫將Twitter整合到我的iPhone應用程序中。使用以下包含的代碼,我可以讓用戶登錄到Twitter。MGTwitter會話
if(_engine) return;
_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
_engine.consumerKey = @"XXXXXX";
_engine.consumerSecret = @"XXXXXXXXX";
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine: _engine delegate: self];
if (controller)
{
[self presentModalViewController: controller animated: YES];
}
我也有處理回調的下列委託方法。
#pragma mark SA_OAuthTwitterEngineDelegate
- (void) storeCachedTwitterOAuthData: (NSString *) data forUsername: (NSString *) username {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject: data forKey: @"authData"];
[defaults synchronize];
}
- (NSString *) cachedTwitterOAuthDataForUsername: (NSString *) username {
return [[NSUserDefaults standardUserDefaults] objectForKey: @"authData"];
}
#pragma mark SA_OAuthTwitterController Delegate
- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username {
NSLog(@"Authenticated with user %@", username);
//tweets = [[NSMutableArray alloc] init];
[self updateStream:nil];
}
- (void) OAuthTwitterControllerFailed: (SA_OAuthTwitterController *) controller {
NSLog(@"Authentication Failure");
}
- (void) OAuthTwitterControllerCanceled: (SA_OAuthTwitterController *) controller {
NSLog(@"Authentication Canceled");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
的用戶可以使用下面的代碼鳴叫:
[_engine sendUpdate:@"Tweet"];
如果我試圖從另一個類或迴歸用戶創建另一個引擎這一切都似乎很標準,但由於某些原因,用戶被迫重新登錄以創建可用的引擎。我錯過了什麼?
我不確定是否在編寫上述問題時犯了一個錯誤,但是如果您創建了該類的另一個實例,那麼它就像運行新程序並且沒有數據存儲一樣,所以如果您試圖包含要使用的文件會話等,那麼你不需要創建一個新的類的實例。 –