问题
in my IOS application I have an in-app purchase in my app and I need to send receipt to my web service to assign premium content to a user account. I need this to be reliable even when the connection is lost right after the in-app purchase completes.
Are there any solid libraries out there that can take a request and execute it when connection is reestablished?
回答1:
I would definitely recommend AFNetworking, a very well-made networking library which wraps NSURLConnection.
In order to use it for your purpose you need to take advantage of the reachability build-in features of AFHTTPClient
as suggested in this other answer.
Basically you can execute and arbitrary block whenever the reachability status of the network changes using the setReachabilityStatusChangeBlock:
method of AFHTTPClient
.
Just remember to link and import the SystemConfiguration
framework, otherwise it won't work.
来源:https://stackoverflow.com/questions/13811022/ios-best-way-to-queue-requests-to-be-sent-when-connection-is-reestablished