2016-06-28 47 views
0

我正在實施可操作的推送操作。點擊行爲後,我得到以下方法。在handleActionWithIdentifier中更快的調用http:forRemoteNotification?

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler { 



     NSError *error; 
     NSDictionary* jsonDict = [[NSMutableDictionary alloc] init]; 
     [jsonDict setValue:[[jsonArray1 valueForKey:@"uid"] lowercaseString] forKey:@"actionby"]; 
     [jsonDict setValue:@"" forKey:@"alid"]; 
     [jsonDict setValue:strOTP forKey:@"tp"]; 
     [jsonDict setValue:@"1" forKey:@"txf"]; 
     NSData* jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict 
                  options:NSJSONWritingPrettyPrinted error:&error]; 

     NSString *str = [[NSString alloc] initWithData:jsonData encoding:NSASCIIStringEncoding]; 

     NSString *trimmedTweet = [str stringByReplacingOccurrencesOfString:@"\n" withString:@" "]; 
     NSString *nospaceStr = [trimmedTweet stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 

     NSString *encrypted [email protected]""; 

      encrypted = [sharedData testSecKey:nospaceStr]; 

      if([encrypted length] > 0) { 

       encrypted = [NSString stringWithFormat:@"enc{%@}",encrypted]; 

       NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", [SharedData getGatewayURL]]] 
                     cachePolicy:NSURLRequestUseProtocolCachePolicy 
                    timeoutInterval:15]; 
       [request setHTTPMethod:@"POST"]; 

       NSString *encodedXML = [encrypted urlEncodeUsingEncoding:NSUTF8StringEncoding]; 

       NSString *params = [NSString stringWithFormat:@"%@=%@", REQUEST_PARAMETER_NAME, encodedXML]; 
       [request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]]; 



       NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES]; 
       [conn start]; 


     if (completionHandler) { 
      completionHandler(); 
     } 

    } 

也處理委託方法。但是在後臺這個響應太慢了(我必須打2個Web服務)?如何解決這個問題?如何加快響應速度?

+0

創建組合Web服務...... – Wain

+0

@Wain。感謝您的迴應。但它需要超過分鐘。仍然無法得到迴應。可能是什麼問題? NSURLConnection是否正常? –

+1

如果可以,您應該使用URL會話 – Wain

回答

0

嗯,我缺失

if (completionHandler) { 
      completionHandler(); 
} 

我叫這個,當我最後一次迴應表格服務器。瞭解iOS完成我的後臺任務。

相關問題