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... ;)

..., IdComponent, IdTCPClient;

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


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

; // Failure - No Internet Connection

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

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

procedure TForm2.TCPClientStatus(ASender: TObject; const AStatus: TIdStatus; const AStatusText: string);
if Pos('Connecting to',AStatusText) > 0 then
// We have reachability to the AppStore, so go ahead and call LoadProducts


  • Guest
    jiang Tuesday, 25 June 2013

    Hi,Anders, Could you share the third party component or the links of it?

  • Guest
    olecramoak Wednesday, 26 June 2013

    hello Anders! Why 3rd party and not direct head parsing with phil hess tools? Currently, I know two apps live on Appstore developed with firemonkey that use Storekit smoothly (there even is a function for testing store reachability)...maybe a more direct approach would be more efficient.

  • Guest
    Blong Thursday, 27 June 2013

    I don't think start is the cause of the exception. You should find that request:didFailWithError: gets called if there is no connectivity.

    Granted it gets called with a useless empty error object, but it gets called nevertheless.

    The question is whether the 3rd party code catches that delegate method, and maybe whether it assumes there is something useful in the error object, checks for nil etc.

  • Guest
    Anders Ohlsson Saturday, 29 June 2013

    @ole: I didn't feel like re-inventing the wheel... ;)

    @Brian: This is actually before that. As soon as start is called with no connection it crashes hard - the exception handling doesn't even get to it. Could still be in the 3rd party component though. No fail event whatsoever.

  • Guest
    Olecramoak Sunday, 30 June 2013

    @anders: but this wheel isn't rolling very well...still a polygon with not near-infinite sides

  • Guest
    jiang Monday, 1 July 2013

    I put the third component in a Form, then compile the project. but it's failed: [DCC Fatal Error] F2051 Unit IOSapi.StoreKit was compiled with a different version of Macapi.ObjectiveC.TOCGenericImport`2.GetOCClass

    tears once more!!!

  • Guest
    Tom Marchione Sunday, 15 September 2013

    Has anyone successfully installed the IAP component in XE5? I am having difficulty. Offhand, it appears that XE5 includes some sort of StoreKit support that was not in XE4, and requires implentation of a certain interface method called "paymentQueueUpdatedDownloads". Am I seeing things? Has anyone made this work in XE5 yet?

  • Guest
    Tom Marchione Sunday, 15 September 2013

    To follow up on my last comment, if you remove the reference to StoreKit in the IAP package, and implement "paymentQueueUpdatedDownloads" and "paymentQueueUpdatedTransactions" in FMX.IAP.IOS, the component will compile and install in XE5. However, I am not familiar with the internals of StoreKit, so I am not entirely sure what the above methods should do.

  • Guest
    Tom Marchione Monday, 16 September 2013

    One more follow-up... I contacted the IAP developer (who is extremely responsive, BTW -- a pleasure to deal with). He confirmed that XE5 has an incomplete implementation of StoreKit in the RTL, which is conflicting with his component. He created a workaround by renaming one of his units, which removes the conflict and allows the component's StoreKit implementation to coexist peacefully with the incomplete references in the XE5 RTL. Problem solved. That said, I don't know if the methods that are not implemented in his component but are required in the native XE5 interface are worth investigating someday. For now, I am mainly interested in moving my development to XE5, so that I can sunset XE4. And this seems to accomplish that.

  • Please login first in order for you to submit comments
  • Page :
  • 1

Check out more tips and tricks in this development video: