forked from organicmaps/organicmaps
[MAPSME-2994] [ios] Added networking policy.
This commit is contained in:
parent
9a46619dc2
commit
5bcc41bf6f
3 changed files with 99 additions and 0 deletions
18
iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.h
Normal file
18
iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.h
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "std/function.hpp"
|
||||
|
||||
namespace networking_policy
|
||||
{
|
||||
using MWMNetworkingPolicyFn = function<void(BOOL solver)>;
|
||||
|
||||
void callPartnersApiWithNetworkingPolicy(MWMNetworkingPolicyFn const & fn);
|
||||
|
||||
enum class NetworkingPolicyState
|
||||
{
|
||||
Always,
|
||||
Session,
|
||||
Never
|
||||
};
|
||||
|
||||
void SetNetworkingPolicyState(NetworkingPolicyState state);
|
||||
NetworkingPolicyState GetNetworkingPolicyState();
|
||||
} // namespace networking_policy
|
65
iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.mm
Normal file
65
iphone/Maps/Classes/NetworkingPolicy/MWMNetworkingPolicy.mm
Normal file
|
@ -0,0 +1,65 @@
|
|||
#import "MWMNetworkingPolicy.h"
|
||||
#import "MWMAlertViewController.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
NSString * const kNetworkingPolicyTimeStamp = @"NetworkingPolicyTimeStamp";
|
||||
NSTimeInterval const kSessionDurationSeconds = 24 * 60 * 60;
|
||||
} // namespace
|
||||
|
||||
namespace networking_policy
|
||||
{
|
||||
void callPartnersApiWithNetworkingPolicy(MWMNetworkingPolicyFn const & fn)
|
||||
{
|
||||
auto checkAndApply = ^BOOL {
|
||||
NSUserDefaults * ud = [NSUserDefaults standardUserDefaults];
|
||||
NSDate * policyDate = [ud objectForKey:kNetworkingPolicyTimeStamp];
|
||||
if ([policyDate compare:[NSDate date]] == NSOrderedDescending)
|
||||
{
|
||||
fn(YES);
|
||||
return YES;
|
||||
}
|
||||
if ([policyDate isEqualToDate:NSDate.distantPast])
|
||||
{
|
||||
fn(NO);
|
||||
return YES;
|
||||
}
|
||||
return NO;
|
||||
};
|
||||
|
||||
if (checkAndApply())
|
||||
return;
|
||||
|
||||
MWMAlertViewController * alertController = [MWMAlertViewController activeAlertController];
|
||||
[alertController presentMobileInternetAlertWithBlock:^{
|
||||
if (!checkAndApply())
|
||||
fn(NO);
|
||||
}];
|
||||
}
|
||||
|
||||
void SetNetworkingPolicyState(NetworkingPolicyState state)
|
||||
{
|
||||
NSUserDefaults * ud = [NSUserDefaults standardUserDefaults];
|
||||
NSDate * policyDate = nil;
|
||||
switch (state)
|
||||
{
|
||||
case NetworkingPolicyState::Always: policyDate = NSDate.distantFuture; break;
|
||||
case NetworkingPolicyState::Session:
|
||||
policyDate = [NSDate dateWithTimeIntervalSinceNow:kSessionDurationSeconds];
|
||||
break;
|
||||
case NetworkingPolicyState::Never: policyDate = NSDate.distantPast; break;
|
||||
}
|
||||
[ud setObject:policyDate forKey:kNetworkingPolicyTimeStamp];
|
||||
}
|
||||
|
||||
NetworkingPolicyState GetNetworkingPolicyState()
|
||||
{
|
||||
NSUserDefaults * ud = [NSUserDefaults standardUserDefaults];
|
||||
NSDate * policyDate = [ud objectForKey:kNetworkingPolicyTimeStamp];
|
||||
if ([policyDate isEqualToDate:NSDate.distantFuture])
|
||||
return NetworkingPolicyState::Always;
|
||||
if ([policyDate isEqualToDate:NSDate.distantPast])
|
||||
return NetworkingPolicyState::Never;
|
||||
return NetworkingPolicyState::Session;
|
||||
}
|
||||
} // namespace networking_policy
|
|
@ -233,6 +233,8 @@
|
|||
349A13831DEC138C00C7DB60 /* MWMMobileInternetAlert.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A13801DEC138C00C7DB60 /* MWMMobileInternetAlert.mm */; };
|
||||
349A13841DEC138C00C7DB60 /* MWMMobileInternetAlert.xib in Resources */ = {isa = PBXBuildFile; fileRef = 349A13811DEC138C00C7DB60 /* MWMMobileInternetAlert.xib */; };
|
||||
349A13851DEC138C00C7DB60 /* MWMMobileInternetAlert.xib in Resources */ = {isa = PBXBuildFile; fileRef = 349A13811DEC138C00C7DB60 /* MWMMobileInternetAlert.xib */; };
|
||||
349A13891DEC44C600C7DB60 /* MWMNetworkingPolicy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A13881DEC44C600C7DB60 /* MWMNetworkingPolicy.mm */; };
|
||||
349A138A1DEC44C600C7DB60 /* MWMNetworkingPolicy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A13881DEC44C600C7DB60 /* MWMNetworkingPolicy.mm */; };
|
||||
349A357A1B53D4C9009677EE /* MWMCircularProgress.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A35761B53D4C9009677EE /* MWMCircularProgress.mm */; };
|
||||
349A357B1B53D4C9009677EE /* MWMCircularProgress.xib in Resources */ = {isa = PBXBuildFile; fileRef = 349A35771B53D4C9009677EE /* MWMCircularProgress.xib */; };
|
||||
349A357C1B53D4C9009677EE /* MWMCircularProgressView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 349A35791B53D4C9009677EE /* MWMCircularProgressView.mm */; };
|
||||
|
@ -1194,6 +1196,8 @@
|
|||
349A137F1DEC138C00C7DB60 /* MWMMobileInternetAlert.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMMobileInternetAlert.h; sourceTree = "<group>"; };
|
||||
349A13801DEC138C00C7DB60 /* MWMMobileInternetAlert.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMMobileInternetAlert.mm; sourceTree = "<group>"; };
|
||||
349A13811DEC138C00C7DB60 /* MWMMobileInternetAlert.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMMobileInternetAlert.xib; sourceTree = "<group>"; };
|
||||
349A13871DEC44C600C7DB60 /* MWMNetworkingPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMNetworkingPolicy.h; sourceTree = "<group>"; };
|
||||
349A13881DEC44C600C7DB60 /* MWMNetworkingPolicy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMNetworkingPolicy.mm; sourceTree = "<group>"; };
|
||||
349A35751B53D4C9009677EE /* MWMCircularProgress.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMCircularProgress.h; sourceTree = "<group>"; };
|
||||
349A35761B53D4C9009677EE /* MWMCircularProgress.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMCircularProgress.mm; sourceTree = "<group>"; };
|
||||
349A35771B53D4C9009677EE /* MWMCircularProgress.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MWMCircularProgress.xib; sourceTree = "<group>"; };
|
||||
|
@ -1884,6 +1888,7 @@
|
|||
080E96DDFE201D6D7F000001 /* Classes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
349A13861DEC448500C7DB60 /* NetworkingPolicy */,
|
||||
348868F01D87DF8C0069BBA3 /* Keyboard */,
|
||||
3436FE7F1D366CA0005CD87B /* Search */,
|
||||
344D77B11D1BD79700DBED70 /* Location */,
|
||||
|
@ -2411,6 +2416,15 @@
|
|||
path = MobileInternetAlert;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
349A13861DEC448500C7DB60 /* NetworkingPolicy */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
349A13871DEC44C600C7DB60 /* MWMNetworkingPolicy.h */,
|
||||
349A13881DEC44C600C7DB60 /* MWMNetworkingPolicy.mm */,
|
||||
);
|
||||
path = NetworkingPolicy;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
349A35741B53D4C9009677EE /* CircularProgress */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -4042,6 +4056,7 @@
|
|||
3418CEAE1CBF9E3300641B25 /* MWMNoMapsViewController.mm in Sources */,
|
||||
3401CD7D1C3CF1BE0028C6F8 /* MWMEditorSwitchTableViewCell.mm in Sources */,
|
||||
34B82AD61B84746E00180497 /* MWMSearchSuggestionCell.mm in Sources */,
|
||||
349A13891DEC44C600C7DB60 /* MWMNetworkingPolicy.mm in Sources */,
|
||||
F6C641B01C15BBE6008FCAF3 /* MWMRecentTrackSettingsController.mm in Sources */,
|
||||
341F99F11C6B4288001C67B8 /* MWMMapDownloaderSearchDataSource.mm in Sources */,
|
||||
34A759D81DC795D10078C3AE /* MWMWhatsNewUberController.mm in Sources */,
|
||||
|
@ -4293,6 +4308,7 @@
|
|||
34EC270B1CB2A7120084FA36 /* fabric_logging_ios.mm in Sources */,
|
||||
6741A9FA1BF340DE002C974C /* MWMBookmarkColorViewController.mm in Sources */,
|
||||
3418CEAF1CBF9E3300641B25 /* MWMNoMapsViewController.mm in Sources */,
|
||||
349A138A1DEC44C600C7DB60 /* MWMNetworkingPolicy.mm in Sources */,
|
||||
3401CD7E1C3CF1BE0028C6F8 /* MWMEditorSwitchTableViewCell.mm in Sources */,
|
||||
34EB84591C073DF70004689F /* MWMOpeningHoursEditorViewController.mm in Sources */,
|
||||
341F99F21C6B4288001C67B8 /* MWMMapDownloaderSearchDataSource.mm in Sources */,
|
||||
|
|
Loading…
Add table
Reference in a new issue