1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
| / Appel Web services ...
//username and password value
NSString *username = @"webservice";
NSString *password = @"byebye";
//HTTP Basic Authentication
NSString *authenticationString = [NSString stringWithFormat:@"%@:%@", username, password];
NSData *authenticationData = [authenticationString dataUsingEncoding:NSASCIIStringEncoding];
NSString *authenticationValue = [authenticationData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
//Set up your request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"//site/index.php/getGlobalStatus/L1"]];
// Set your user login credentials
[request setValue:[NSString stringWithFormat:@"Basic %@", authenticationValue] forHTTPHeaderField:@"Authorization"];
// Send your request asynchronously
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *responseCode, NSData *responseData, NSError *responseError)
{
if (responseData.length > 0 && responseError == nil)
{
//NSLog(@"value data : %@", responseData);
NSDictionary *greeting = [NSJSONSerialization JSONObjectWithData:responseData
options:0
error:NULL];
//NSLog(@"passe ...");
NSLog(@"value greeting: %@", greeting);
self.greetingdateDerniereSauvegarde = [greeting objectForKey:@"dateDerniereSauvegarde"] ;
self.greetingetatGlobalStatus = [greeting objectForKey:@"etatGlobalStatus"];
self.greetingnomMachine = [greeting objectForKey:@"nomMachine"];
NSLog(@"dataRecup : %@", self.greetingdateDerniereSauvegarde);
NSLog(@"dataRecup : %@", self.greetingetatGlobalStatus);
NSLog(@"dataRecup : %@", self.greetingnomMachine);
}
else if ([responseData length] == 0 && responseError == nil)
{
NSLog(@"Nothing was downloaded.");
}
else if (responseError != nil){
NSLog(@"Error de connexion = %@", responseError);
}
if ([self.greetingetatGlobalStatus isEqual: @"OK"] ) {
[statusItem setImage:statusImageOk];
[statusItem setToolTip:@"Sauvegarde effectuée."];
}else {
[statusItem setImage:statusImageNok];
[statusItem setToolTip:@"Sauvegarde pas effectuée. Veuillez patienter svp maximum 2 jours ..."];
}
}]; |