Delphi iOS IPv6的麻烦。请确保您的应用与IPv6网络兼容

时间:2017-04-05 22:11:14

标签: ios delphi networking indy

我无法将我的iOS应用发布到AppStore。

Delphi 10.1.2 Berlin,iOS64,Win 8.1。

我收到了苹果的下一个信息:

  

感谢您的回复。

     

请确保您的应用与IPv6网络兼容。

     

测试应用以实现IPv6兼容性的最简单方法是在Mac上设置本地IPv6网络。然后,您可以从iOS设备连接到网络以测试IPv6兼容性。

     

请按照支持IPv6 DNS64 / NAT64网络中提供的分步说明进行操作。

     

有关支持IPv6网络的其他信息,请查看支持仅IPv6网络。

它的连接代码。

     if (FSocket<>nil) then
     begin
          if not FSocket.Connected then
          begin
               SetState(mwtrstDisConnected);
               FSocket.Free;
               FSocket:=nil;
          end
          else
              exit;
     end;

     FSocket:=TIdTCPClient.Create(nil);
     FSocket.Host:=FHost;
     FSocket.Port:=FPort;

//CheckCode


{$ifdef KBMMW_USING_INDY_9_OR_NEWER}
     FSocket.BoundPortMin:=FMinClientPort;
     FSocket.BoundPortMax:=FMaxClientPort;
{$endif}

{$IFDEF KBMMW_USING_INDY_10}
     FSocket.ReadTimeout:=RequestTimeout*1000;
     FSocket.ConnectTimeout:=ConnectTimeout*1000;
{$ENDIF}
{$IFDEF KBMMW_USING_INDY_8_00_23}
     FSocket.Connect;
{$ELSE}
 {$IFDEF KBMMW_USING_INDY_9}
     FSocket.Connect(ConnectTimeout*1000);
 {$ELSE}
     FSocket.Connect;
 {$ENDIF}
{$ENDIF}
     DoConnected(Info);

在我看来,我必须在// CheckCode中插入下一个代码。

  TIdStack.IncUsage;
  IdURI := TIdURI.Create('195.34.x.x');
  try
    try
      ss := GStack.ResolveHost(IdURI.Host, TIdIPVersion.Id_IPv6);
      IdURI.IPVersion := TIdIPVersion.Id_IPv6;
    except
      IdURI.IPVersion := TIdIPVersion.Id_IPv4; // Just in case.
    end;

    //ShowMessage(ss);
  finally
    FreeAndNil(IdURI);
    TIdStack.DecUsage;
  end;

但是这段代码(GStack.ResolveHost)并不适用于iOS。

如何解决?

1 个答案:

答案 0 :(得分:0)

尝试更像这样的东西:

FSocket := TIdTCPClient.Create(nil);
FSocket.Host := FHost;
FSocket.Port := FPort;

{$IFDEF KBMMW_USING_INDY_9_OR_NEWER}
FSocket.BoundPortMin := FMinClientPort;
FSocket.BoundPortMax := FMaxClientPort;
{$ENDIF}

{$IFDEF KBMMW_USING_INDY_10}
FSocket.ReadTimeout := RequestTimeout*1000;
FSocket.ConnectTimeout := ConnectTimeout*1000;

// check if connecting to an IPv4/IPv6 address directly...
if GStack.IsIP(FHost) then // only checks for IPv4 right now
begin
  FSocket.IPVersion := Id_IPv4;
  FSocket.Connect;
end
else if MakeCanonicalIPv6Address(FHost) <> '' then
begin
  FSocket.IPVersion := Id_IPv6;
  FSocket.Connect;
end
else begin
  // connecting to a hostname, try IPv6 first, then fallback to IPv4...
  try
    FSocket.IPVersion := Id_IPv6;
    FSocket.Connect;
  except
    FSocket.IPVersion := Id_IPv4;
    FSocket.Connect;
  end;
end;
{$ELSE}
  // only IPv4 is supported...
  {$IFDEF KBMMW_USING_INDY_9}
FSocket.Connect(ConnectTimeout*1000);
  {$ELSE}
FSocket.Connect;
  {$ENDIF}
{$ENDIF}

DoConnected(Info);

可替换地:

var
  LIPAddress: TIdIPAddress;
  LLocalIPs: TIdStackLocalAddressList;
  TryIPv4, TryIPv6: Boolean;
  I: Integer;

...

FSocket := TIdTCPClient.Create(nil);
FSocket.Host := FHost;
FSocket.Port := FPort;

{$IFDEF KBMMW_USING_INDY_9_OR_NEWER}
FSocket.BoundPortMin := FMinClientPort;
FSocket.BoundPortMax := FMaxClientPort;
{$ENDIF}

{$IFDEF KBMMW_USING_INDY_10}
FSocket.ReadTimeout := RequestTimeout*1000;
FSocket.ConnectTimeout := ConnectTimeout*1000;

LIPAddress := TIdIPAddress.MakeAddressObject(FHost);
if LIPAddress <> nil then
begin
  // connecting to an IPv4/IPv6 address...
  FSocket.IPVersion := LIPAddress.AddrType;
  LIPAddress.Free;
  FSocket.Connect;
end else
begin
  // connecting to a hostname...

  TryIPv4 := False;
  TryIPv6 := False;

  LLocalIPs := TIdStackLocalAddressList.Create;
  try
    GStack.GetLocalAddressList(LLocalIPs);
    for I := 0 to LLocalIPs.Count-1 do
    begin
      case LLocalIPs[I].IPVersion of
        Id_IPv4: TryIPv4 := True;
        Id_IPv6: TryIPv6 := True;
      end;
    end;
  finally
    List.Free;
  end;

  if TryIPv6 then
  begin
    try
      FSocket.IPVersion := Id_IPv6;
      FSocket.Connect;
      TryIPv4 := False;
    except
      if not TryIPv4 then
        raise;
    end;
  end;

  if TryIPv4 then
  begin
    FSocket.IPVersion := Id_IPv4;
    FSocket.Connect;
  end;

  if not (TryIPv4 or TryIPv6) then
    raise Exception.Create('Not connected to an IPv4 or IPv6 network');
end;
{$ELSE}
  // only IPv4 is supported...
  {$IFDEF KBMMW_USING_INDY_9}
FSocket.Connect(ConnectTimeout*1000);
  {$ELSE}
FSocket.Connect;
  {$ENDIF}
{$ENDIF}

DoConnected(Info);

请注意,一旦Indy实现了以下功能,这种情况就会变得更加简单,但我认为这是一个方法:

Support round-robin DNS (support connecting to IPv4/IPv6 hostnames)