登录多个设备时 XMPP 资源 ID 发生变化

XMPP resource id getting change while login more then one device

我已经用相同的用户名和密码登录了两台设备,所以当目标设备向客户端发送语音或图像时。一台设备收到目标消息而另一台设备没有收到目标消息。因为在两个设备中登录时资源 ID 正在发生变化。它显示错误消息 503()

 (NSString *)full
{
  if (user)
  {
    if (resource)
    {
      //----- here i am getting the resource ID -------
        [[NSUserDefaults standardUserDefaults]setObject:resource forKey:@"GETRESOURCE"];
        [[NSUserDefaults standardUserDefaults]synchronize];

        return [NSString stringWithFormat:@"%@@%@/%@", user, domain, resource];
    }
    else
    {
        return [NSString stringWithFormat:@"%@@%@", user, domain];
    }
  } else {
    if (resource)
        return [NSString stringWithFormat:@"%@/%@", domain, resource];
    else
        return domain;
  }
}  



(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
  CGFloat maxCompression = 0.1f;

  NSData *imageData = UIImageJPEGRepresentation([info objectForKey:UIImagePickerControllerOriginalImage], maxCompression);
[messageType addObject:@"1"];

  //---- now implementing the resource id here i getting 503 Error----
  NSString *resourceStr = [[NSUserDefaults standardUserDefaults] valueForKey:@"GETRESOURCE"];

  XMPPJID *jid = [XMPPJID jidWithString:[NSString stringWithFormat:@"%@/%@", receiver, resourceStr]];

  [fileTransfer initiateFileTransferTo:jid withData:imageData];

  self.willSendImage = [UIImage imageWithData:imageData];
  [messageArray addObject:[NSDictionary dictionaryWithObject:self.willSendImage forKey:@"image"]];
  [self.timestamps addObject:[NSDate date]];

  NSDate *currDate = [NSDate date];
  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
  [dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss Z"];
  NSString *dateString = [dateFormatter stringFromDate:currDate];

  [dbHandler insertChatHistory:@"image" imageData:imageData receiveType:2 mediaType:2 receiverName:titleName date:dateString];

  [self finishSend];
  [JSMessageSoundEffect playMessageSentSound];
  [self scrollToBottomAnimated:YES];
  [self reloadMessages];

  [self dismissViewControllerAnimated:YES completion:NULL];

}

//--- 我将以字符串格式发送图像,它对我有用

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{



    CGFloat maxCompression = 0.1f;

    UIImage * getimage =[self imageWithImage:[info objectForKey:UIImagePickerControllerOriginalImage]];
    NSData *imageData = UIImageJPEGRepresentation(getimage, maxCompression);

    NSDate *currDate = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss Z"];
    NSString *dateString = [dateFormatter stringFromDate:currDate];


    //--- convert image to string -----

    NSString* imageString = [imageData base64EncodedStringWithOptions:0];
    //---- new change --

    imageString = [imageString stringByAppendingString:@".IMAGE"];

    //-------------

    if ([imageString length] > 0)
    {
        [dbHandler insertChatHistory:imageString imageData:nil receiveType:2 mediaType:1 receiverName:titleName date:dateString];

        NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
        [body setStringValue:imageString];

        NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
        [message addAttributeWithName:@"type" stringValue:@"chat"];
        [message addAttributeWithName:@"to" stringValue:receiver]; //--- jenish ---
        [message addChild:body];
        [self.xmppStream sendElement:message];

        [messageType addObject:@"1"];
        [messageArray addObject:[NSDictionary dictionaryWithObject:imageString forKey:@"Text"]];
        [self.timestamps addObject:[NSDate date]];

    }

    [self finishSend];
    [JSMessageSoundEffect playMessageSentSound];
    [self scrollToBottomAnimated:YES];
    [self reloadMessages];

    [self dismissViewControllerAnimated:YES completion:NULL];

}