Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Khmurets <subzero@mapswithme.com>2014-08-06 18:53:47 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:23:43 +0300
commit5642b6b5cc254bb63bc50573753abdb950db8e62 (patch)
tree5e4aef2c4a368e8b34bb73ba639d0f99d3885a3c /iphone/Maps/Classes/LocalNotificationManager.mm
parent61ba34aa10d26473775448960e8f21444a093020 (diff)
[ios] Promo notification in Lite
Diffstat (limited to 'iphone/Maps/Classes/LocalNotificationManager.mm')
-rw-r--r--iphone/Maps/Classes/LocalNotificationManager.mm57
1 files changed, 49 insertions, 8 deletions
diff --git a/iphone/Maps/Classes/LocalNotificationManager.mm b/iphone/Maps/Classes/LocalNotificationManager.mm
index eb9bf7212b..cddca3f963 100644
--- a/iphone/Maps/Classes/LocalNotificationManager.mm
+++ b/iphone/Maps/Classes/LocalNotificationManager.mm
@@ -6,8 +6,11 @@
#import "LocationManager.h"
#import "MapViewController.h"
#import "Statistics.h"
+#import "UIKitCategories.h"
#define DOWNLOAD_MAP_ACTION_NAME @"DownloadMapAction"
+#define PROMO_ACTION_NAME @"PromoAction"
+
#define FLAGS_KEY @"DownloadMapNotificationFlags"
#define SHOW_INTERVAL (6 * 30 * 24 * 60 * 60) // six months
@@ -19,7 +22,7 @@ typedef void (^CompletionHandler)(UIBackgroundFetchResult);
@property (nonatomic) CLLocationManager * locationManager;
@property (nonatomic) TIndex countryIndex;
-@property (nonatomic, copy) CompletionHandler completionHandler;
+@property (nonatomic, copy) CompletionHandler downloadMapCompletionHandler;
@property (nonatomic) NSTimer * timer;
@end
@@ -55,25 +58,24 @@ typedef void (^CompletionHandler)(UIBackgroundFetchResult);
[self markNotificationShowingForIndex:index];
UILocalNotification * notification = [[UILocalNotification alloc] init];
- notification.fireDate = [NSDate date];
notification.alertAction = NSLocalizedString(@"download", nil);
notification.alertBody = NSLocalizedString(@"download_map_notification", nil);
notification.soundName = UILocalNotificationDefaultSoundName;
notification.userInfo = @{@"Action" : DOWNLOAD_MAP_ACTION_NAME, @"Group" : @(index.m_group), @"Country" : @(index.m_country), @"Region" : @(index.m_region)};
UIApplication * application = [UIApplication sharedApplication];
- [application scheduleLocalNotification:notification];
+ [application presentLocalNotificationNow:notification];
[[Statistics instance] logEvent:@"'Download Map' Notification Scheduled"];
// we don't need badges now
// [application setApplicationIconBadgeNumber:[application applicationIconBadgeNumber] + 1];
- self.completionHandler(UIBackgroundFetchResultNewData);
+ self.downloadMapCompletionHandler(UIBackgroundFetchResultNewData);
return;
}
}
}
[[Statistics instance] logEvent:@"'Download Map' Notification Didn't Schedule" withParameters:@{@"WiFi" : @(onWiFi)}];
- self.completionHandler(UIBackgroundFetchResultFailed);
+ self.downloadMapCompletionHandler(UIBackgroundFetchResultFailed);
}
- (void)markNotificationShowingForIndex:(TIndex)index
@@ -97,7 +99,7 @@ typedef void (^CompletionHandler)(UIBackgroundFetchResult);
- (void)showDownloadMapNotificationIfNeeded:(void (^)(UIBackgroundFetchResult))completionHandler
{
- self.completionHandler = completionHandler;
+ self.downloadMapCompletionHandler = completionHandler;
self.timer = [NSTimer scheduledTimerWithTimeInterval:20 target:self selector:@selector(timerSelector:) userInfo:nil repeats:NO];
if ([CLLocationManager locationServicesEnabled])
[self.locationManager startUpdatingLocation];
@@ -108,7 +110,7 @@ typedef void (^CompletionHandler)(UIBackgroundFetchResult);
- (void)timerSelector:(id)sender
{
// we have not got time to get location
- self.completionHandler(UIBackgroundFetchResultFailed);
+ self.downloadMapCompletionHandler(UIBackgroundFetchResultFailed);
}
- (void)downloadCountryWithIndex:(TIndex)index
@@ -122,7 +124,7 @@ typedef void (^CompletionHandler)(UIBackgroundFetchResult);
f.ShowRect(lat, lon, 10);
}
-- (void)processDownloadMapNotification:(UILocalNotification *)notification
+- (void)processNotification:(UILocalNotification *)notification
{
NSDictionary * ui = [notification userInfo];
if ([ui[@"Action"] isEqualToString:DOWNLOAD_MAP_ACTION_NAME])
@@ -133,6 +135,45 @@ typedef void (^CompletionHandler)(UIBackgroundFetchResult);
TIndex const index = TIndex([ui[@"Group"] intValue], [ui[@"Country"] intValue], [ui[@"Region"] intValue]);
[self downloadCountryWithIndex:index];
}
+ else if ([ui[@"Action"] isEqualToString:PROMO_ACTION_NAME])
+ {
+ [[Statistics instance] logEvent:@"'Promo' Notification Clicked"];
+ [[UIApplication sharedApplication] openProVersionFrom:@"ios_promo_notif"];
+ }
+}
+
+- (void)schedulePromoNotification
+{
+ if (GetPlatform().IsPro())
+ return;
+
+ UIApplication * application = [UIApplication sharedApplication];
+
+ if ([application canOpenURL:[NSURL URLWithString:MAPSWITHME_PREMIUM_LOCAL_URL]])
+ return;
+
+ for (UILocalNotification * notification in application.scheduledLocalNotifications)
+ {
+ if ([notification.userInfo[@"Action"] isEqualToString:PROMO_ACTION_NAME])
+ return;
+ }
+
+ NSDateComponents * components = [[NSDateComponents alloc] init];
+ [components setYear:2014];
+ [components setMonth:8];
+ [components setDay:15];
+ [components setHour:12];
+ NSDate * date = [[NSCalendar currentCalendar] dateFromComponents:components];
+ if ([date timeIntervalSinceNow] > 0) {
+ UILocalNotification * notification = [[UILocalNotification alloc] init];
+ notification.fireDate = [[NSCalendar currentCalendar] dateFromComponents:components];
+ notification.alertBody = NSLocalizedString(@"pro_version_is_free_today", nil);
+ notification.soundName = UILocalNotificationDefaultSoundName;
+ notification.userInfo = @{@"Action" : PROMO_ACTION_NAME};
+
+ [application scheduleLocalNotification:notification];
+ [[Statistics instance] logEvent:@"'Promo' Notification Scheduled"];
+ }
}
- (void)showDownloadMapAlertIfNeeded