[MAPSME-3810] [ios] Added CanUseNetwork check to NetworkPolicy.

This commit is contained in:
Ilya Grechuhin 2017-02-10 10:52:03 +03:00 committed by Sergey Yershov
parent d43d6ac2d6
commit 708527f268
2 changed files with 14 additions and 0 deletions

View file

@ -8,4 +8,6 @@ void CallPartnersApi(platform::PartnersApiFn fn, bool force = false);
void SetStage(platform::NetworkPolicy::Stage state);
platform::NetworkPolicy::Stage GetStage();
bool CanUseNetwork();
} // namespace network_policy

View file

@ -78,4 +78,16 @@ np::Stage GetStage()
return np::Stage::Never;
return np::Stage::Session;
}
bool CanUseNetwork()
{
auto const connectionType = GetPlatform().ConnectionStatus();
if (connectionType == Platform::EConnectionType::CONNECTION_NONE)
return false;
if (connectionType == Platform::EConnectionType::CONNECTION_WIFI)
return true;
NSUserDefaults * ud = [NSUserDefaults standardUserDefaults];
NSDate * policyDate = [ud objectForKey:kNetworkingPolicyTimeStamp];
return [policyDate compare:[NSDate date]] == NSOrderedDescending;
}
} // namespace network_policy