问题描述
我在我的 iOS 和 Android 应用程序中编写了一个函数来打开一个 url.我相信此代码会因未通过 IPv6 连接而被 iTunes Connect 拒绝.
I have written a function in my iOS and Android apps to open a url. I believe this code will be rejected by iTunes Connect for not connecting over IPv6.
这个函数在我通过 Delphi 构建时也会引发错误:
This function also raises an error when I build it through Delphi:
在错误地址 00000001017C4334 处发生访问冲突.(访问地址000000000000000时)
我使用的是带有 Indy 10 的 Delphi 10.2.3 Tokyo.
I am using Delphi 10.2.3 Tokyo with Indy 10.
我该如何解决这个错误?我的代码如下:
How can I fix this error? My code is below:
Procedure OpenGoogleForm;
Var
ipversion : String;
Begin
// For IPv6
IdTCPClient1.IPVersion:=Id_IPv4; // <-- try IPv4 first
IdTCPClient1.Host:=MY_IP;
try
IdTCPClient1.Connect;
result:=true;
ipversion := 'IPv4'; // <-- will tell us what ip version to use
except
end;
if IdTCPClient1.Connected=false then
begin
try
IdTCPClient1.IPVersion:=Id_IPv6; // <-- now try IPv6
IdTCPClient1.Connect;
result:=true;
ipversion:='IPv6'; // <-- will tell us what ip version to use
except
end;
end;
// open url
{$IFDEF ANDROID}
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
Intent.setData(StrToJURI('https://docs.google.com/forms/xxxx'));
SharedActivity.startActivity(Intent);
{$ENDIF}
{$IFDEF IOS}
SharedApplication.openURL(StrToNSUrl('https://docs.google.com/forms/xxxx'));
{$ENDIF}
End;
推荐答案
错误消息告诉您正在访问 nil
指针,因此您需要找到它.
The error message is telling you that a nil
pointer is being accessed, so you need to hunt that down.
但是,根本没有理由在打开网址之前执行手动 TCP 检查.您正在生成一个外部应用程序来打开 url,因此让该应用程序根据需要处理连接错误.特别是因为如果两个 Connect()
调用都失败了,你还是会继续打开 url.因此,只需从您的过程中完全摆脱 TIdTCPClient
,它不属于那里.这可能是您的 nil
指针的来源.
But, there is no reason at all to perform a manual TCP check before opening a url. You are spawning an external app to open the url, so let that app handle connectivity errors as it needs. Especially since you proceed to open the url anyway if both Connect()
calls fail. So just get rid of TIdTCPClient
from your procedure altogether, it doesn't belong there. That is probably where your nil
pointer is coming from.
procedure OpenGoogleForm;
begin
{$IFDEF ANDROID}
Intent := TJIntent.Create;
Intent.setAction(TJIntent.JavaClass.ACTION_VIEW);
Intent.setData(StrToJURI('https://docs.google.com/forms/xxxx'));
SharedActivity.startActivity(Intent);
{$ENDIF}
{$IFDEF IOS}
SharedApplication.openURL(StrToNSUrl('https://docs.google.com/forms/xxxx'));
{$ENDIF}
end;
这篇关于如何正确打开 IPv6 上的 url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!