forked from organicmaps/organicmaps
Merge pull request #3828 from igrechuhin/permissions
[ios] Fixed permissions request on app launch.
This commit is contained in:
commit
92923578ab
4 changed files with 59 additions and 71 deletions
|
@ -1,56 +1,39 @@
|
|||
#import "MapsAppDelegate.h"
|
||||
#import "MapViewController.h"
|
||||
#import "MWMFirstLaunchController.h"
|
||||
#import "MWMLocationManager.h"
|
||||
#import "MWMPageController.h"
|
||||
#import "MapViewController.h"
|
||||
#import "MapsAppDelegate.h"
|
||||
|
||||
#include "Framework.h"
|
||||
|
||||
@interface MWMLocationManager ()
|
||||
|
||||
@property (nonatomic) BOOL started;
|
||||
@property(nonatomic) BOOL started;
|
||||
+ (MWMLocationManager *)manager;
|
||||
|
||||
@end
|
||||
|
||||
@interface MWMFirstLaunchController ()
|
||||
|
||||
@property (weak, nonatomic) IBOutlet UIView * containerView;
|
||||
@property (weak, nonatomic) IBOutlet UIImageView * image;
|
||||
@property (weak, nonatomic) IBOutlet UILabel * alertTitle;
|
||||
@property (weak, nonatomic) IBOutlet UILabel * alertText;
|
||||
@property (weak, nonatomic) IBOutlet UIButton * nextPageButton;
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * containerWidth;
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * containerHeight;
|
||||
@property(weak, nonatomic) IBOutlet UIView * containerView;
|
||||
@property(weak, nonatomic) IBOutlet UIImageView * image;
|
||||
@property(weak, nonatomic) IBOutlet UILabel * alertTitle;
|
||||
@property(weak, nonatomic) IBOutlet UILabel * alertText;
|
||||
@property(weak, nonatomic) IBOutlet UIButton * nextPageButton;
|
||||
@property(weak, nonatomic) IBOutlet NSLayoutConstraint * containerWidth;
|
||||
@property(weak, nonatomic) IBOutlet NSLayoutConstraint * containerHeight;
|
||||
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * imageMinHeight;
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * imageHeight;
|
||||
@property(weak, nonatomic) IBOutlet NSLayoutConstraint * imageMinHeight;
|
||||
@property(weak, nonatomic) IBOutlet NSLayoutConstraint * imageHeight;
|
||||
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * titleTopOffset;
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint * titleImageOffset;
|
||||
@property(weak, nonatomic) IBOutlet NSLayoutConstraint * titleTopOffset;
|
||||
@property(weak, nonatomic) IBOutlet NSLayoutConstraint * titleImageOffset;
|
||||
|
||||
@end
|
||||
|
||||
namespace
|
||||
{
|
||||
void requestNotifications()
|
||||
{
|
||||
UIApplication * app = [UIApplication sharedApplication];
|
||||
UIUserNotificationType userNotificationTypes =
|
||||
(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
|
||||
if ([app respondsToSelector:@selector(registerUserNotificationSettings:)])
|
||||
{
|
||||
UIUserNotificationSettings * settings =
|
||||
[UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
|
||||
[app registerUserNotificationSettings:settings];
|
||||
[app registerForRemoteNotifications];
|
||||
}
|
||||
else
|
||||
{
|
||||
[app registerForRemoteNotificationTypes:userNotificationTypes];
|
||||
}
|
||||
}
|
||||
|
||||
void requestNotifications() { [MapsAppDelegate initPushNotificationsWithLaunchOptions:nil]; }
|
||||
void zoomToCurrentPosition()
|
||||
{
|
||||
auto & f = GetFramework();
|
||||
|
@ -66,8 +49,7 @@ NSInteger constexpr kRequestLocationPage = 2;
|
|||
NSInteger constexpr kRequestNotificationsPage = 3;
|
||||
|
||||
NSArray<TMWMWelcomeConfigBlock> * pagesConfigBlocks = @[
|
||||
[^(MWMFirstLaunchController * controller)
|
||||
{
|
||||
[^(MWMFirstLaunchController * controller) {
|
||||
controller.image.image = [UIImage imageNamed:@"img_onboarding_offline_maps"];
|
||||
controller.alertTitle.text = L(@"onboarding_offline_maps_title");
|
||||
controller.alertText.text = L(@"onboarding_offline_maps_message");
|
||||
|
@ -76,8 +58,7 @@ NSArray<TMWMWelcomeConfigBlock> * pagesConfigBlocks = @[
|
|||
action:@selector(nextPage)
|
||||
forControlEvents:UIControlEventTouchUpInside];
|
||||
} copy],
|
||||
[^(MWMFirstLaunchController * controller)
|
||||
{
|
||||
[^(MWMFirstLaunchController * controller) {
|
||||
controller.image.image = [UIImage imageNamed:@"img_onboarding_geoposition"];
|
||||
controller.alertTitle.text = L(@"onboarding_location_title");
|
||||
controller.alertText.text = L(@"onboarding_location_message");
|
||||
|
@ -86,8 +67,7 @@ NSArray<TMWMWelcomeConfigBlock> * pagesConfigBlocks = @[
|
|||
action:@selector(nextPage)
|
||||
forControlEvents:UIControlEventTouchUpInside];
|
||||
} copy],
|
||||
[^(MWMFirstLaunchController * controller)
|
||||
{
|
||||
[^(MWMFirstLaunchController * controller) {
|
||||
controller.image.image = [UIImage imageNamed:@"img_onboarding_notification"];
|
||||
controller.alertTitle.text = L(@"onboarding_notifications_title");
|
||||
controller.alertText.text = L(@"onboarding_notifications_message");
|
||||
|
@ -96,8 +76,7 @@ NSArray<TMWMWelcomeConfigBlock> * pagesConfigBlocks = @[
|
|||
action:@selector(nextPage)
|
||||
forControlEvents:UIControlEventTouchUpInside];
|
||||
} copy],
|
||||
[^(MWMFirstLaunchController * controller)
|
||||
{
|
||||
[^(MWMFirstLaunchController * controller) {
|
||||
controller.image.image = [UIImage imageNamed:@"img_onboarding_done"];
|
||||
controller.alertTitle.text = L(@"first_launch_congrats_title");
|
||||
controller.alertText.text = L(@"first_launch_congrats_text");
|
||||
|
@ -107,20 +86,12 @@ NSArray<TMWMWelcomeConfigBlock> * pagesConfigBlocks = @[
|
|||
forControlEvents:UIControlEventTouchUpInside];
|
||||
} copy]
|
||||
];
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@implementation MWMFirstLaunchController
|
||||
|
||||
+ (NSString *)udWelcomeWasShownKey
|
||||
{
|
||||
return @"FirstLaunchWelcomeWasShown";
|
||||
}
|
||||
|
||||
+ (NSArray<TMWMWelcomeConfigBlock> *)pagesConfig
|
||||
{
|
||||
return pagesConfigBlocks;
|
||||
}
|
||||
|
||||
+ (NSString *)udWelcomeWasShownKey { return @"FirstLaunchWelcomeWasShown"; }
|
||||
+ (NSArray<TMWMWelcomeConfigBlock> *)pagesConfig { return pagesConfigBlocks; }
|
||||
- (void)viewWillAppear:(BOOL)animated
|
||||
{
|
||||
[super viewWillAppear:animated];
|
||||
|
@ -130,11 +101,7 @@ NSArray<TMWMWelcomeConfigBlock> * pagesConfigBlocks = @[
|
|||
requestNotifications();
|
||||
}
|
||||
|
||||
- (void)requestLocation
|
||||
{
|
||||
[MWMLocationManager manager].started = YES;
|
||||
}
|
||||
|
||||
- (void)requestLocation { [MWMLocationManager manager].started = YES; }
|
||||
- (void)close
|
||||
{
|
||||
[self.pageController close];
|
||||
|
@ -150,7 +117,8 @@ NSArray<TMWMWelcomeConfigBlock> * pagesConfigBlocks = @[
|
|||
CGFloat const width = newSize.width;
|
||||
CGFloat const height = newSize.height;
|
||||
BOOL const hideImage = (self.imageHeight.multiplier * height <= self.imageMinHeight.constant);
|
||||
self.titleImageOffset.priority = hideImage ? UILayoutPriorityDefaultLow : UILayoutPriorityDefaultHigh;
|
||||
self.titleImageOffset.priority =
|
||||
hideImage ? UILayoutPriorityDefaultLow : UILayoutPriorityDefaultHigh;
|
||||
self.image.hidden = hideImage;
|
||||
self.containerWidth.constant = width;
|
||||
self.containerHeight.constant = height;
|
||||
|
|
|
@ -140,6 +140,20 @@ void sendInfoToFramework(dispatch_block_t block)
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
NSString * const kLocationPermissionRequestedKey = @"kLocationPermissionRequestedKey";
|
||||
|
||||
BOOL isPermissionRequested()
|
||||
{
|
||||
return [[NSUserDefaults standardUserDefaults] boolForKey:kLocationPermissionRequestedKey];
|
||||
}
|
||||
|
||||
void setPermissionRequested()
|
||||
{
|
||||
NSUserDefaults * ud = [NSUserDefaults standardUserDefaults];
|
||||
[ud setBool:YES forKey:kLocationPermissionRequestedKey];
|
||||
[ud synchronize];
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@interface MWMLocationManager ()<CLLocationManagerDelegate>
|
||||
|
@ -199,13 +213,13 @@ void sendInfoToFramework(dispatch_block_t block)
|
|||
|
||||
+ (void)applicationDidBecomeActive
|
||||
{
|
||||
if (![Alohalytics isFirstSession])
|
||||
if (isPermissionRequested())
|
||||
[MWMLocationManager manager].started = YES;
|
||||
}
|
||||
|
||||
+ (void)applicationWillResignActive
|
||||
{
|
||||
BOOL const keepRunning = keepRunningInBackground();
|
||||
BOOL const keepRunning = isPermissionRequested() && keepRunningInBackground();
|
||||
MWMLocationManager * manager = [MWMLocationManager manager];
|
||||
CLLocationManager * locationManager = manager.locationManager;
|
||||
if ([locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)])
|
||||
|
@ -490,6 +504,7 @@ void sendInfoToFramework(dispatch_block_t block)
|
|||
if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
|
||||
[locationManager requestWhenInUseAuthorization];
|
||||
[locationManager startUpdatingLocation];
|
||||
setPermissionRequested();
|
||||
if ([CLLocationManager headingAvailable])
|
||||
[locationManager startUpdatingHeading];
|
||||
};
|
||||
|
|
|
@ -8,16 +8,15 @@
|
|||
@class MapViewController;
|
||||
@class LocationManager;
|
||||
|
||||
typedef NS_ENUM(NSUInteger, MWMRoutingPlaneMode)
|
||||
{
|
||||
typedef NS_ENUM(NSUInteger, MWMRoutingPlaneMode) {
|
||||
MWMRoutingPlaneModeNone,
|
||||
MWMRoutingPlaneModePlacePage,
|
||||
MWMRoutingPlaneModeSearchSource,
|
||||
MWMRoutingPlaneModeSearchDestination
|
||||
};
|
||||
|
||||
@interface MapsAppDelegate : UIResponder<UIApplicationDelegate, UIAlertViewDelegate,
|
||||
DownloadIndicatorProtocol>
|
||||
@interface MapsAppDelegate
|
||||
: UIResponder<UIApplicationDelegate, UIAlertViewDelegate, DownloadIndicatorProtocol>
|
||||
{
|
||||
NSInteger m_activeDownloadsCounter;
|
||||
UIBackgroundTaskIdentifier m_backgroundTask;
|
||||
|
@ -25,14 +24,16 @@ typedef NS_ENUM(NSUInteger, MWMRoutingPlaneMode)
|
|||
UIAlertView * m_loadingAlertView;
|
||||
}
|
||||
|
||||
@property (nonatomic) UIWindow * window;
|
||||
@property (nonatomic) MWMRoutingPlaneMode routingPlaneMode;
|
||||
@property(nonatomic) UIWindow * window;
|
||||
@property(nonatomic) MWMRoutingPlaneMode routingPlaneMode;
|
||||
|
||||
@property (nonatomic, readonly) MapViewController * mapViewController;
|
||||
@property (nonatomic, readonly) BOOL isDrapeEngineCreated;
|
||||
@property(nonatomic, readonly) MapViewController * mapViewController;
|
||||
@property(nonatomic, readonly) BOOL isDrapeEngineCreated;
|
||||
|
||||
+ (MapsAppDelegate *)theApp;
|
||||
|
||||
+ (void)initPushNotificationsWithLaunchOptions:(NSDictionary *)launchOptions;
|
||||
|
||||
- (void)enableStandby;
|
||||
- (void)disableStandby;
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ using namespace osm_auth_ios;
|
|||
|
||||
#pragma mark - Notifications
|
||||
|
||||
- (void)initPushNotificationsWithLaunchOptions:(NSDictionary *)launchOptions
|
||||
+ (void)initPushNotificationsWithLaunchOptions:(NSDictionary *)launchOptions
|
||||
{
|
||||
// Do not initialize Pushwoosh for open-source version.
|
||||
if (string(PUSHWOOSH_APPLICATION_ID).empty())
|
||||
|
@ -178,8 +178,8 @@ using namespace osm_auth_ios;
|
|||
objectForInfoDictionaryKey:@"CFBundleDisplayName"]];
|
||||
PushNotificationManager * pushManager = [PushNotificationManager pushManager];
|
||||
|
||||
// handling push on app start
|
||||
[pushManager handlePushReceived:launchOptions];
|
||||
if (launchOptions)
|
||||
[pushManager handlePushReceived:launchOptions];
|
||||
|
||||
// make sure we count app open in Pushwoosh stats
|
||||
[pushManager sendAppOpen];
|
||||
|
@ -431,7 +431,6 @@ using namespace osm_auth_ios;
|
|||
|
||||
GetFramework().EnterForeground();
|
||||
|
||||
[self initPushNotificationsWithLaunchOptions:launchOptions];
|
||||
[self commonInit];
|
||||
|
||||
LocalNotificationManager * notificationManager = [LocalNotificationManager sharedManager];
|
||||
|
@ -441,9 +440,14 @@ using namespace osm_auth_ios;
|
|||
onLaunch:YES];
|
||||
|
||||
if ([Alohalytics isFirstSession])
|
||||
{
|
||||
[self firstLaunchSetup];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self incrementSessionsCountAndCheckForAlert];
|
||||
[MapsAppDelegate initPushNotificationsWithLaunchOptions:launchOptions];
|
||||
}
|
||||
|
||||
[self enableTTSForTheFirstTime];
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue