In-App Purchase: SKRequest.start bug?

Posted by on in Blogs
Since I'm using a third party component for In-App Purchasing, I'm not sure where this bug is, but it seems that SKRequest.start crashes when there is no connectivity to the Internet in general (or to the AppStore in particular).

My solution is to check for reachability to the AppStore, because that's what we really care about. I'm using Indy for a multi-platform solution (as opposed to iOS APIs).

I offer the following code up as a solution. Tear it apart... ;)


uses
..., IdComponent, IdTCPClient;

type
TForm2 = class(TForm)
...
public
Conn : TIdTCPClient;
procedure TCPClientStatus(ASender: TObject; const AStatus: TIdStatus; const AStatusText: string);
procedure TCPClientConnected(Sender: TObject);
procedure TCPClientDisconnected(Sender: TObject);
end;

implementation

procedure TForm2.Button1Click(Sender: TObject);
begin
// Attempt to connect to the AppStore
Conn := TIdTCPClient.Create(nil);
Conn.Host := 'itunes.apple.com';
Conn.Port := 80;
Conn.OnConnected := TCPClientConnected;
Conn.OnDisconnected := TCPClientDisconnected;
Conn.OnStatus := TCPClientStatus;

try
Conn.Connect;
except
; // Failure - No Internet Connection
end;
end;

procedure TForm2.TCPClientConnected(Sender: TObject);
begin
// Disconnect gracefully
Conn.Disconnect;
end;

procedure TForm2.TCPClientDisconnected(Sender: TObject);
begin
// No need for this TCP client anymore
Conn.DisposeOf;
end;

procedure TForm2.TCPClientStatus(ASender: TObject; const AStatus: TIdStatus; const AStatusText: string);
begin
if Pos('Connecting to',AStatusText) > 0 then
// We have reachability to the AppStore, so go ahead and call LoadProducts
InAppPurchase1.LoadProducts;
end;
Comments are not available for public users. Please login first to view / add comments.