Does method report(_:withCompletionHandler:) send score even if your internet connection was lost?

86 Views Asked by At

I have a question about GKScore. There is a method called report(_:withCompletionHandler:). What happens if you lose your Internet connection. Do I need to save my score and submit it later? Or the method itself solves it. Is it not automatically sent in the background? Thanks in advance

2

There are 2 best solutions below

0
On BEST ANSWER

From Apple's Game Center programming documentation:

Your game should create the score object and report the score to Game Center immediately after the score is earned. This sets the date and time accurately and ensures that the score is reported correctly. If for some reason the score could not be reported because of a network error, Game Kit automatically resends the data when the network becomes available.

So you don't have to do anything. Reference to the docs is here.

0
On

Yo can try it putting the plane mode.

But if you try to call this method without internet it will return an error.

You could get the internet connection status using the reachability. If you use Alamofire it have integrate a very good reachability system.

If your game need internet to play you can block your principal screen using:

import Alamofire

extension NetworkReachabilityManager {
    static var isConnectedToInternet: Bool {
        return NetworkReachabilityManager().isReachable
    }
}

Else you can save your request to send it when you have internet. The NetworkReachabilityManager will send you a notification when internet was enable and disable.