我正在執行一些與網絡相關的代碼。當代碼開始執行並且用戶在後臺發送應用程序時,如果異常提示應用程序被終止。如果沒有提出異常,應用程序不會被殺死。是否有可能停止/暫停任何類型的網絡活動?或者阻止應用程序被殺的方法?如果在後臺引發NSException會拋出應用程序
UPDATE
我使用書面uncaughtexception處理亞光gallahar(可可愛)。一旦它被解僱,我該如何取消這個請求。對於要求輸入密碼在此功能
+(NSString*)validate:(NSString*)username password:(NSString*)password server:(NSString*)server port:(int)port encryption:(int)encryption authentication:(int)authentication folders:(NSMutableArray*)folders {
CTCoreAccount* account = [[CTCoreAccount alloc] init];
@try {
[account connectToServer:server port:port connectionType:encryption authType:authentication login:username password:password];
} @catch (NSException *exp) {
NSLog(@"connect exception: %@", exp);
return [NSString stringWithFormat:@"Connect error: %@", [ImapFolderWorker decodeError:exp]];
}
}
- (void)connectToServer:(NSString *)server port:(int)port
connectionType:(int)conType authType:(int)authType
login:(NSString *)login password:(NSString *)password {
int err = 0;
int imap_cached = 0;
const char* auth_type_to_pass = NULL;
if(authType == IMAP_AUTH_TYPE_SASL_CRAM_MD5) {
auth_type_to_pass = "CRAM-MD5";
}
err = imap_mailstorage_init_sasl(myStorage,
(char *)[server cStringUsingEncoding:NSUTF8StringEncoding],
(uint16_t)port, NULL,
conType,
auth_type_to_pass,
NULL,
NULL, NULL,
(char *)[login cStringUsingEncoding:NSUTF8StringEncoding], (char *)[login cStringUsingEncoding:NSUTF8StringEncoding],
(char *)[password cStringUsingEncoding:NSUTF8StringEncoding], NULL,
imap_cached, NULL);
if (err != MAIL_NO_ERROR) {
NSException *exception = [NSException
exceptionWithName:CTMemoryError
reason:CTMemoryErrorDesc
userInfo:nil];
[exception raise];
}
err = mailstorage_connect(myStorage);
if (err == MAIL_ERROR_LOGIN) {
NSException *exception = [NSException
exceptionWithName:CTLoginError
reason:CTLoginErrorDesc
userInfo:nil];
[exception raise];
}
else if (err != MAIL_NO_ERROR) {
NSException *exception = [NSException
exceptionWithName:CTUnknownError
reason:[NSString stringWithFormat:@"Error number: %d",err]
userInfo:nil];
[exception raise];
}
else
connected = YES;
}
被稱爲異常發生。如果我進入不同的端口號時異常在下面的行
NSException *exception = [NSException
exceptionWithName:CTUnknownError
reason:[NSString stringWithFormat:@"Error number: %d",err]
userInfo:nil];
[exception raise]; // this line kills the app if the app is in background.
這些功能在MailCore圖書館提高。現在如果有人知道解決方案,請幫助我。
什麼是異常名稱? – joerick 2012-02-28 11:59:17
@joerick查看更新後的問題 – 2012-02-29 04:15:09