Je construis un scrobbler des médias. Ce que je veux que le programme fasse est de détecter le média d'iTunes/MPlayer et que le programme envoie une mise à jour via l'API. J'ai noté cette partie, mais lorsque le même titre média et segment (piste/épisode) est comparé à cette instruction If, il reprend la même action, ce que je ne veux pas que le programme fasse.Problème avec les instructions If
Voici le code problématique que je vais par:
if ([[segment stringValue] length] == 0 || [[mediatitle stringValue]length] == 0) {
// Do Nothing
}
else if ([mediatitle stringValue] == ScrobbledMediaTitle && [segment stringValue] == ScrobbledMediaSegment && scrobblesuccess == 1) {
// Do Nothing
}
else {
int httperror = [self scrobble];
switch (httperror) {
case 200:
[scrobblestatus setObjectValue:@"Scrobble Successful..."];
[GrowlApplicationBridge notifyWithTitle:@"Scrobble Successful"
description:[NSString stringWithFormat:@"%@ - %@", [mediatitle stringValue], [segment stringValue]]
notificationName:@"Message"
iconData:nil
priority:0
isSticky:NO
clickContext:[NSDate date]];
ScrobbledMediaTitle = [mediatitle stringValue];
ScrobbledMediaSegment = [segment stringValue];
scrobblesuccess = YES;
//Set up Delegate
Melative_ExampleAppDelegate* appDelegate=[NSApp delegate];
//Set last successful scrobble to statusItem Tooltip
[appDelegate setStatusToolTip:[NSString stringWithFormat:@"MelScrobbleX - Last Scrobble: %@ - %@", [mediatitle stringValue], [segment stringValue]]];
NSLog(@"ScrobbledMediaTitle = %@", ScrobbledMediaTitle);
NSLog(@"ScrobbledMediaSegment = %@" , ScrobbledMediaSegment);
NSLog(@"BOOL = %d", (int)scrobblesuccess);
break;
case 401:
// Set Status
[scrobblestatus setObjectValue:@"Unable to Scrobble..."];
[GrowlApplicationBridge notifyWithTitle:@"Scrobble Unsuccessful"
description:@"Check your login information and try scrobbling again."
notificationName:@"Message"
iconData:nil
priority:0
isSticky:NO
clickContext:[NSDate date]];
scrobblesuccess = NO;
break;
default:
// Set Status
[scrobblestatus setObjectValue:@"Unable to Scrobble..."];
[GrowlApplicationBridge notifyWithTitle:@"Scrobble Unsuccessful"
description:[NSString stringWithFormat:@"Unknown Error. Error %i", httperror]
notificationName:@"Message"
iconData:nil
priority:0
isSticky:NO
clickContext:[NSDate date]];
scrobblesuccess = NO;
break;
}
}
}
J'essaie de déterminer avec la sortie NSLog et c'est ce que je reçois:
2010-08-01 21:58:56.935 MelScrobbleX[7775:a0f] ScrobbledMediaTitle = (null)
2010-08-01 21:58:56.935 MelScrobbleX[7775:a0f] ScrobbledMediaSegment = (null)
2010-08-01 21:58:56.935 MelScrobbleX[7775:a0f] BOOL = 0
2010-08-01 21:58:56.935 MelScrobbleX[7775:a0f] mediatitle = Lia COLLECTION ALBUM "SPECTRUM RAYS"
2010-08-01 21:58:56.936 MelScrobbleX[7775:a0f] mediasegment = Tori no Uta -StripE REMIX-
2010-08-01 21:58:56.936 MelScrobbleX[7775:a0f] Scrobbled
2010-08-01 21:58:56.936 MelScrobbleX[7775:a0f] ScrobbledMediaTitle = Lia COLLECTION ALBUM "SPECTRUM RAYS"
2010-08-01 21:58:56.936 MelScrobbleX[7775:a0f] ScrobbledMediaSegment = Tori no Uta -StripE REMIX-
2010-08-01 21:58:56.936 MelScrobbleX[7775:a0f] BOOL = 1
2010-08-01 21:59:06.709 MelScrobbleX[7775:a0f] ScrobbledMediaTitle = Lia COLLECTION ALBUM "SPECTRUM RAYS"
2010-08-01 21:59:06.709 MelScrobbleX[7775:a0f] ScrobbledMediaSegment = Tori no Uta -StripE REMIX-
2010-08-01 21:59:06.710 MelScrobbleX[7775:a0f] BOOL = 1
2010-08-01 21:59:06.710 MelScrobbleX[7775:a0f] mediatitle = Lia COLLECTION ALBUM "SPECTRUM RAYS"
2010-08-01 21:59:06.710 MelScrobbleX[7775:a0f] mediasegment = Tori no Uta -StripE REMIX-
2010-08-01 21:59:06.711 MelScrobbleX[7775:a0f] Scrobbled
2010-08-01 21:59:06.711 MelScrobbleX[7775:a0f] ScrobbledMediaTitle = Lia COLLECTION ALBUM "SPECTRUM RAYS"
2010-08-01 21:59:06.711 MelScrobbleX[7775:a0f] ScrobbledMediaSegment = Tori no Uta -StripE REMIX-
2010-08-01 21:59:06.711 MelScrobbleX[7775:a0f] BOOL = 1
ne peux pas comprendre la raison pour laquelle l'instruction IF ne se déclencherait pas puisque les valeurs sont les mêmes et scrobbleSuccess est vrai.
Je viens de publier votre message. La prochaine fois, s'il vous plaît, formater le code – vodkhang
Objectif-C me fait mal aux yeux ... –
Désolé pour ça ... Il ne colle pas correctement ...> _ < – chikorita157