这是对推特请求的回复。我在问这个问题后使用了这段代码。我不需要查看 Skype API,因为它工作得很好,但我想自从我上次尝试使用它以来它已经更新了。无论如何...
这是我与 Skype 通信时使用的 NSDistributedNotifications 列表:
SKSkypeAPI通知
SKSkype附加响应
SKSkype变得可用
SKA可用性更新
SKSkypeWillQuit
就像任何其他类型的 NSDistributedNotification 一样,您只需注册并处理结果:
[[NSDistributedNotificationCenter defaultCenter]
addObserver:self selector:@selector(setStatusAfterQuit:)
name:@"SKSkypeWillQuit"
object:nil
suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];
这些是我与 Skype 保持同步的 iVar:
NSString *applicationName;
NSString *mostRecentStatus;
NSString *mostRecentStatusMessage;
NSString *mostRecentUsername;
int APIClientID;
BOOL isConnected;
BOOL needToSetMessage;
NSString *nextMessage;
NSString *nextStatus;
以下是如何连接到 Skype 的示例:
-(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 = @"";
}
}
}
}