Это ответ в ответ на запрос из твиттера. Я использовал этот код после того, как задал этот вопрос. Мне не нужно было заглядывать в Skype API, поскольку он работает просто отлично, но я думаю, что он был обновлен с тех пор, как я в последний раз пытался его использовать. Так или иначе ...
Вот список NSDistributedNotifications, которые я использую при общении с Skype:
SKSkypeAPINotification
SKSkypeAttachResponse
SKSkypeBecameAvailable
SKAvailabilityUpdate
SKSkypeWillQuit
Как и любой другой вид NSDistributedNotification, вы просто регистрируете и обрабатываете результаты:
[[NSDistributedNotificationCenter defaultCenter]
addObserver:self selector:@selector(setStatusAfterQuit:)
name:@"SKSkypeWillQuit"
object:nil
suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];
Это iVars, которые я продолжаю синхронизировать со Skype:
NSString *applicationName;
NSString *mostRecentStatus;
NSString *mostRecentStatusMessage;
NSString *mostRecentUsername;
int APIClientID;
BOOL isConnected;
BOOL needToSetMessage;
NSString *nextMessage;
NSString *nextStatus;
Вот пример подключения к скайпу:
-(void) skypeConnect{
if (!isConnected){
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"SKSkypeAPIAvailabilityRequest"
object:nil
userInfo:nil
deliverImmediately:YES];
[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"SKSkypeAPIAttachRequest"
object:applicationName
userInfo:nil
deliverImmediately:YES];
}
}
Вот пример получения сообщения о статусе (после регистрации в Skype):
-(void) processNotification:(NSNotification *) note{
if ([[note name] isEqualToString:@"SKSkypeAttachResponse"]){
if([[[note userInfo] objectForKey:@"SKYPE_API_ATTACH_RESPONSE"] intValue] == 0){
NSLog(@"Failed to connect to Skype.");
isConnected = NO;
}else {
NSLog(@"Connected to Skype.");
APIClientID = [[[note userInfo] objectForKey:@"SKYPE_API_ATTACH_RESPONSE"] intValue];
isConnected = YES;
[self sendCommand:@"GET PROFILE MOOD_TEXT"];
if (needToSetMessage){
[self sendCommand:[NSString stringWithFormat:@"SET USERSTATUS %@",nextStatus]];
[self sendCommand:[NSString stringWithFormat:@"SET PROFILE MOOD_TEXT %@",nextMessage]];
needToSetMessage = NO;
nextMessage = @"";
nextStatus = @"";
}
}
}
}