Yes, you can use a class provided by Apple called Reachability to verify the internet connection status, and NSNotificationCenter to keep waiting for any internet connection status. Thus, you could send the scores to your mysql database using the methods described above by @trojanfoe.
To verify internet status first check if any host is reachable, if it is, we understand that there is an internet connection:
- (BOOL)verifyInternetStatus
{
Reachability *reachable = [Reachability reachabilityWithHostName:@"www.google.com"];
NetworkStatus internetStatus = [r currentReachabilityStatus];
if (internetStatus == NotReachable) {
// there's not internet connection, therefore we save the scores locally
}
else {
// send the scores to the database
}
}
When the internet status changes, Reachability class notifies to its observers through NSNotificationCenter that internet status has changed using the key kReachabilityChangedNotification
. So, you need to add your class as an observer of this key:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(verifyInternetStatus:)
name:kReachabilityChangedNotification
object:nil];
This is one way to doing so. When you want to send the score, call the method verifyInternetStatus
it will send the score or will save it locally.
I hope it helps.
EDIT:
Sorry, i've forgot the class:
https://developer.apple.com/iphone/library/samplecode/Reachability/index.html