diff --git a/iphone/Maps/Classes/LocalNotificationInfoProvider.h b/iphone/Maps/Classes/LocalNotificationInfoProvider.h deleted file mode 100644 index 9c1b1929ef..0000000000 --- a/iphone/Maps/Classes/LocalNotificationInfoProvider.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// LocalNotificationInfoProvider.h -// Maps -// -// Created by Timur Bernikowich on 25/11/2014. -// Copyright (c) 2014 MapsWithMe. All rights reserved. -// - -#import - -@interface LocalNotificationInfoProvider : NSObject - -- (instancetype)initWithDictionary:(NSDictionary *)info; - -@property (nonatomic) NSDictionary * info; - -@end \ No newline at end of file diff --git a/iphone/Maps/Classes/LocalNotificationInfoProvider.m b/iphone/Maps/Classes/LocalNotificationInfoProvider.m deleted file mode 100644 index 20b2fa9543..0000000000 --- a/iphone/Maps/Classes/LocalNotificationInfoProvider.m +++ /dev/null @@ -1,48 +0,0 @@ -// -// LocalNotificationInfoProvider.m -// Maps -// -// Created by Timur Bernikowich on 25/11/2014. -// Copyright (c) 2014 MapsWithMe. All rights reserved. -// - -#import "LocalNotificationInfoProvider.h" -#import "UIKitCategories.h" - -@implementation LocalNotificationInfoProvider - -- (instancetype)initWithDictionary:(NSDictionary *)info -{ - self = [super init]; - if (self) - _info = info; - return self; -} - -#pragma mark - Activity Item Source - -- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController -{ - return [NSString string]; -} - -- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType -{ - NSString * textToShare; - if ([activityType isEqualToString:UIActivityTypeMail]) - textToShare = L(self.info[@"NotificationLocalizedShareEmailBodyKey"]); - else - textToShare = L(self.info[@"NotificationLocalizedShareTextKey"]); - NSURL * link = [NSURL URLWithString:self.info[@"NotificationShareLink"]]; - if (link) - textToShare = [textToShare stringByAppendingFormat:@" %@", [link absoluteString]]; - return textToShare; -} - -- (NSString *)activityViewController:(UIActivityViewController *)activityViewController subjectForActivityType:(NSString *)activityType -{ - NSString * emailSubject = L(self.info[@"NotificationLocalizedShareEmailSubjectKey"]); - return emailSubject; -} - -@end \ No newline at end of file diff --git a/iphone/Maps/Classes/LocalNotificationManager.h b/iphone/Maps/Classes/LocalNotificationManager.h index bebef86c3d..cd909b676d 100644 --- a/iphone/Maps/Classes/LocalNotificationManager.h +++ b/iphone/Maps/Classes/LocalNotificationManager.h @@ -6,7 +6,6 @@ + (instancetype)sharedManager; - (void)showDownloadMapNotificationIfNeeded:(void (^)(UIBackgroundFetchResult))completionHandler; -- (void)updateLocalNotifications; - (void)processNotification:(UILocalNotification *)notification onLaunch:(BOOL)onLaunch; @end diff --git a/iphone/Maps/Classes/LocalNotificationManager.mm b/iphone/Maps/Classes/LocalNotificationManager.mm index b510634a03..89ff33561d 100644 --- a/iphone/Maps/Classes/LocalNotificationManager.mm +++ b/iphone/Maps/Classes/LocalNotificationManager.mm @@ -1,6 +1,5 @@ #import "Common.h" #import "Framework.h" -#import "LocalNotificationInfoProvider.h" #import "LocalNotificationManager.h" #import "LocationManager.h" #import "MapsAppDelegate.h" @@ -19,9 +18,6 @@ static NSString * kDownloadMapActionName = @"DownloadMapAction"; static NSString * kFlagsKey = @"DownloadMapNotificationFlags"; static constexpr const double kRepeatedNotificationIntervalInSeconds = 3 * 30 * 24 * 60 * 60; // three months -NSString * const LocalNotificationManagerSpecialNotificationInfoKey = @"LocalNotificationManagerSpecialNotificationInfoKey"; -NSString * const LocalNotificationManagerNumberOfViewsPrefix = @"LocalNotificationManagerNumberOfViewsPrefix"; - using namespace storage; typedef void (^CompletionHandler)(UIBackgroundFetchResult); @@ -47,11 +43,6 @@ typedef void (^CompletionHandler)(UIBackgroundFetchResult); return manager; } -- (void)updateLocalNotifications -{ - [self scheduleSpecialLocalNotifications]; -} - - (void)processNotification:(UILocalNotification *)notification onLaunch:(BOOL)onLaunch { NSDictionary * userInfo = [notification userInfo]; @@ -63,175 +54,6 @@ typedef void (^CompletionHandler)(UIBackgroundFetchResult); TIndex const index = TIndex([userInfo[@"Group"] intValue], [userInfo[@"Country"] intValue], [userInfo[@"Region"] intValue]); [self downloadCountryWithIndex:index]; } - else if (userInfo[LocalNotificationManagerSpecialNotificationInfoKey]) - { - NSDictionary * notificationInfo = userInfo[LocalNotificationManagerSpecialNotificationInfoKey]; - if (onLaunch) - [self runNotificationAction:notificationInfo]; - else - { - NSString * dismissiveAction = L(@"later"); - NSString * positiveAction = [self actionTitleWithAction:notificationInfo[@"NotificationAction"]]; - NSString * notificationTitle = L(notificationInfo[@"NotificationLocalizedAlertBodyKey"]); - if (![notificationTitle length]) - notificationTitle = L(notificationInfo[@"NotificationLocalizedBodyKey"]); - UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:notificationTitle message:nil delegate:nil cancelButtonTitle:dismissiveAction otherButtonTitles:positiveAction, nil]; - alertView.tapBlock = ^(UIAlertView *alertView, NSInteger buttonIndex) { - NSString * notificationID = notificationInfo[@"NotificationID"]; - BOOL shared = (buttonIndex != alertView.cancelButtonIndex); - [[Statistics instance] logEvent:[NSString stringWithFormat:@"'%@' Notification Show", notificationID] withParameters:@{@"Shared" : @(shared)}]; - if (shared) - [self runNotificationAction:notificationInfo]; - }; - [alertView show]; - } - } -} - -- (NSString *)actionTitleWithAction:(NSString *)action -{ - if ([action isEqualToString:@"Share"]) - return L(@"share"); - else if ([action isEqualToString:@"AppStoreProVersion"]) - return L(@"download"); - else - return nil; -} - -- (void)runNotificationAction:(NSDictionary *)notificationInfo -{ - NSString * action = notificationInfo[@"NotificationAction"]; - - if ([action isEqualToString:@"Share"]) - { - UIImage * shareImage = [UIImage imageNamed:notificationInfo[@"NotifiicationShareImage"]]; - LocalNotificationInfoProvider * infoProvider = [[LocalNotificationInfoProvider alloc] initWithDictionary:notificationInfo]; - - NSMutableArray * itemsToShare = [NSMutableArray arrayWithObject:infoProvider]; - if (shareImage) - [itemsToShare addObject:shareImage]; - - UIActivityViewController * activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil]; - NSMutableArray * excludedActivityTypes = [@[UIActivityTypePrint, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll] mutableCopy]; - [excludedActivityTypes addObject:UIActivityTypeAirDrop]; - activityVC.excludedActivityTypes = excludedActivityTypes; - UIWindow * window = [[UIApplication sharedApplication].windows firstObject]; - NavigationController * vc = (NavigationController *)window.rootViewController; - [vc presentViewController:activityVC animated:YES completion:nil]; - } -} - -#pragma mark - Special Notifications - -- (BOOL)isSpecialLocalNotification:(UILocalNotification *)notification -{ - if (notification.userInfo && notification.userInfo[LocalNotificationManagerSpecialNotificationInfoKey]) - return YES; - else - return NO; -} - -- (NSArray *)scheduledSpecialLocalNotifications -{ - NSArray * allNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications]; - NSMutableArray * specialNotifications = [[NSMutableArray alloc] init]; - for (UILocalNotification * notification in allNotifications) - { - if ([self isSpecialLocalNotification:notification]) - [specialNotifications addObject:notification]; - } - - return specialNotifications; -} - -- (BOOL)isSpecialNotificationScheduled:(NSString *)specialNotificationID -{ - NSArray * notifications = [self scheduledSpecialLocalNotifications]; - - for (UILocalNotification * scheduledNotification in notifications) - { - NSDictionary * notificationInfo = scheduledNotification.userInfo[LocalNotificationManagerSpecialNotificationInfoKey]; - NSString * scheduledSpecialNotificationID = notificationInfo[@"NotificationID"]; - if ([scheduledSpecialNotificationID isEqualToString:specialNotificationID]) - return YES; - } - - return NO; -} - -- (void)increaseViewsNumberOfNotification:(NSString *)specialNotificationID -{ - NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults]; - NSString * key = [NSString stringWithFormat:@"%@%@", LocalNotificationManagerNumberOfViewsPrefix, specialNotificationID]; - NSNumber * viewsNumber = [userDefaults objectForKey:key]; - viewsNumber = viewsNumber ? @([viewsNumber integerValue] + 1) : @(1); - [userDefaults setObject:viewsNumber forKey:key]; - [userDefaults synchronize]; -} - -- (NSNumber *)viewNumberOfNotification:(NSString *)specialNotificationID -{ - NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults]; - NSString * key = [NSString stringWithFormat:@"%@%@", LocalNotificationManagerNumberOfViewsPrefix, specialNotificationID]; - NSNumber * viewsNumber = [userDefaults objectForKey:key]; - if (!viewsNumber) - viewsNumber = @(0); - return viewsNumber; -} - -- (void)scheduleSpecialLocalNotifications -{ - NSArray * localNotificationsInfo = [self localNotificationsInfo]; - NSMutableArray * actualSpecialLocalNotifications = [NSMutableArray array]; - for (NSDictionary * notificationInfo in localNotificationsInfo) - { - NSString * notificationID = notificationInfo[@"NotificationID"]; - if ([self isSpecialNotificationScheduled:notificationID]) - continue; - - NSNumber * viewsLimit = notificationInfo[@"NotificationViewsLimit"]; - NSNumber * viewsNumber = [self viewNumberOfNotification:notificationID]; - if ([viewsNumber integerValue] >= [viewsLimit integerValue]) - continue; - - NSDate * fireDate = [NSDateFormatter dateWithString:notificationInfo[@"NotificationDate"]]; - NSDate * expirationDate = [NSDateFormatter dateWithString:notificationInfo[@"NotificationExpirationDate"]]; - NSDate * currentDate = [NSDate date]; - if (expirationDate && [currentDate timeIntervalSinceDate:expirationDate] >= 0) - continue; - - if ([currentDate timeIntervalSinceDate:fireDate] >= 0) - fireDate = [NSDate dateWithTimeIntervalSinceNow:10.0 * 60]; - - [self increaseViewsNumberOfNotification:notificationID]; - - UILocalNotification * notification = [[UILocalNotification alloc] init]; - notification.alertBody = L(notificationInfo[@"NotificationLocalizedBodyKey"]); - notification.fireDate = fireDate; - notification.soundName = UILocalNotificationDefaultSoundName; - notification.alertAction = L(notificationInfo[@"NotificationActionTitleKey"]); - notification.userInfo = @{LocalNotificationManagerSpecialNotificationInfoKey : notificationInfo}; - - UIApplication * application = [UIApplication sharedApplication]; - [application scheduleLocalNotification:notification]; - [actualSpecialLocalNotifications addObject:notification]; - - [[Statistics instance] logEvent:[NSString stringWithFormat:@"'%@' Notification Scheduled", notificationID]]; - } - - // We'd like to remove not actual special notifications. - NSMutableArray * notActualSpecialLocalNotifications = [[self scheduledSpecialLocalNotifications] mutableCopy]; - [notActualSpecialLocalNotifications removeObjectsInArray:actualSpecialLocalNotifications]; - for (UILocalNotification * notification in notActualSpecialLocalNotifications) - [[UIApplication sharedApplication] cancelLocalNotification:notification]; -} - -- (NSArray *)localNotificationsInfo -{ - NSString * localNotificationsInfoFileName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"LocalNotificationsFileName"]; - NSString * localNotificationsInfoFilePath = [[NSBundle mainBundle] pathForResource:localNotificationsInfoFileName ofType:@"plist"]; - NSArray * localNotificationsInfo = [NSArray arrayWithContentsOfFile:localNotificationsInfoFilePath]; - return localNotificationsInfo; } #pragma mark - Location Notifications diff --git a/iphone/Maps/Classes/MapsAppDelegate.mm b/iphone/Maps/Classes/MapsAppDelegate.mm index 9766a25806..5174c4238e 100644 --- a/iphone/Maps/Classes/MapsAppDelegate.mm +++ b/iphone/Maps/Classes/MapsAppDelegate.mm @@ -234,7 +234,6 @@ void InitLocalizedStrings() LocalNotificationManager * notificationManager = [LocalNotificationManager sharedManager]; if (launchOptions[UIApplicationLaunchOptionsLocalNotificationKey]) [notificationManager processNotification:launchOptions[UIApplicationLaunchOptionsLocalNotificationKey] onLaunch:YES]; - [notificationManager updateLocalNotifications]; if ([Alohalytics isFirstSession]) { diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj index 06d8fe2347..70354422c8 100644 --- a/iphone/Maps/Maps.xcodeproj/project.pbxproj +++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj @@ -178,7 +178,6 @@ B00511021A1101E000A61AA4 /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97C98655186C734000AF7E9E /* AVFoundation.framework */; }; B00511041A1101F600A61AA4 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B00511031A1101F600A61AA4 /* CoreData.framework */; }; B00511061A1101FC00A61AA4 /* CoreMedia.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B00511051A1101FC00A61AA4 /* CoreMedia.framework */; }; - B08AA8CE1A24C7BC00810B1C /* LocalNotificationInfoProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = B08AA8CD1A24C7BC00810B1C /* LocalNotificationInfoProvider.m */; }; B08AA8D51A25E58500810B1C /* PassKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97C9864F186C5EDE00AF7E9E /* PassKit.framework */; settings = {ATTRIBUTES = (Required, ); }; }; B08AA8D61A25E58C00810B1C /* Social.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97C9864D186C5ED300AF7E9E /* Social.framework */; settings = {ATTRIBUTES = (Required, ); }; }; B08AA8DA1A26299A00810B1C /* TimeUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = B08AA8D91A26299A00810B1C /* TimeUtils.m */; }; @@ -566,8 +565,6 @@ A3CC2CD31A1C723900B832E1 /* LocationPredictor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocationPredictor.h; sourceTree = ""; }; B00511031A1101F600A61AA4 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; B00511051A1101FC00A61AA4 /* CoreMedia.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreMedia.framework; path = System/Library/Frameworks/CoreMedia.framework; sourceTree = SDKROOT; }; - B08AA8CC1A24C7BC00810B1C /* LocalNotificationInfoProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalNotificationInfoProvider.h; sourceTree = ""; }; - B08AA8CD1A24C7BC00810B1C /* LocalNotificationInfoProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LocalNotificationInfoProvider.m; sourceTree = ""; }; B08AA8D81A26299A00810B1C /* TimeUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TimeUtils.h; path = Categories/TimeUtils.h; sourceTree = ""; }; B08AA8D91A26299A00810B1C /* TimeUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TimeUtils.m; path = Categories/TimeUtils.m; sourceTree = ""; }; B0DFE6301A1B78A200B6C35E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = en; path = en.lproj/LocalNotifications.plist; sourceTree = ""; }; @@ -855,8 +852,6 @@ FA4135DF120A25B90062D5B4 /* Settings */, 974D041C1977DE430081D0A7 /* LocalNotificationManager.h */, 974D041B1977DE430081D0A7 /* LocalNotificationManager.mm */, - B08AA8CC1A24C7BC00810B1C /* LocalNotificationInfoProvider.h */, - B08AA8CD1A24C7BC00810B1C /* LocalNotificationInfoProvider.m */, B0DFE62F1A1B78A200B6C35E /* LocalNotifications.plist */, B0FBFA251A515AFD0086819E /* ViewController.h */, B0FBFA261A515AFD0086819E /* ViewController.m */, @@ -2213,7 +2208,6 @@ 976D86F119C877E600C920EF /* MapCell.mm in Sources */, F6C934401AE64E4200DDC624 /* MWMSpringAnimation.mm in Sources */, 977E26C219E31BCC00BA2219 /* ActiveMapsVC.mm in Sources */, - B08AA8CE1A24C7BC00810B1C /* LocalNotificationInfoProvider.m in Sources */, 1D3623260D0F684500981E51 /* MapsAppDelegate.mm in Sources */, 341522BF1B666A550077AA8F /* MWMAPIBarView.m in Sources */, 349A35831B53E967009677EE /* MWMDownloadMapRequest.mm in Sources */,