[ios] Added MoreAppsVC

This commit is contained in:
Igor Khmurets 2014-02-12 12:37:01 +03:00 committed by Alex Zolotarev
parent a09a552cbf
commit 14e5664afd
12 changed files with 282 additions and 15 deletions

View file

@ -46,6 +46,7 @@
@interface UIApplication (URLs)
- (void)openProVersion;
- (void)openGuideWithName:(NSString *)guideName itunesURL:(NSString *)itunesURL;
@end

View file

@ -170,6 +170,16 @@
[self openURL:[NSURL URLWithString:MAPSWITHME_PREMIUM_APPSTORE_URL]];
}
- (void)openGuideWithName:(NSString *)guideName itunesURL:(NSString *)itunesURL
{
NSString * guide = [[guideName stringByReplacingOccurrencesOfString:@" " withString:@""] lowercaseString];
NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"guidewithme-%@://", guide]];
if ([self canOpenURL:url])
[self openURL:url];
else
[self openURL:[NSURL URLWithString:itunesURL]];
}
@end

View file

@ -98,8 +98,9 @@ NSString * const MWMProVersionPrefix = @"MWMPro";
}
else
{
NSString * adUnitId = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MoPubInterstitialAdUnitId"];
self.interstitialAd = [MPInterstitialAdController interstitialAdControllerForAdUnitId:adUnitId];
NSDictionary * imageVariants = [[AppInfo sharedInfo] featureValue:[self appFeatureNameForMessage:messageName] forKey:@"Variants"];
NSString * unitId = imageVariants[imageType][@"UnitId"];
self.interstitialAd = [MPInterstitialAdController interstitialAdControllerForAdUnitId:unitId];
self.interstitialAd.delegate = self;
[self.interstitialAd loadAd];
}
@ -119,8 +120,9 @@ NSString * const MWMProVersionPrefix = @"MWMPro";
if ([imageType isEqualToString:MoPubImageType])
{
#ifdef OMIM_LITE
NSString * adUnitId = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MoPubTopBannerAdUnitId"];
MPAdView * moPubBanner = [[MPAdView alloc] initWithAdUnitId:adUnitId size:MOPUB_BANNER_SIZE];
NSDictionary * imageVariants = [[AppInfo sharedInfo] featureValue:[self appFeatureNameForMessage:messageName] forKey:@"Variants"];
NSString * unitId = imageVariants[imageType][@"UnitId"];
MPAdView * moPubBanner = [[MPAdView alloc] initWithAdUnitId:unitId size:MOPUB_BANNER_SIZE];
moPubBanner.hidden = YES;
moPubBanner.delegate = self;
[moPubBanner startAutomaticallyRefreshingContents];

View file

@ -18,6 +18,7 @@
#import "AppInfo.h"
#import "InAppMessagesManager.h"
#import "InterstitialView.h"
#import "MoreAppsVC.h"
#import "../Settings/SettingsManager.h"
#import "../../Common/CustomAlertView.h"
@ -843,6 +844,11 @@ const long long LITE_IDL = 431183278L;
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"unknown_current_position", nil) message:nil delegate:nil cancelButtonTitle:NSLocalizedString(@"ok", nil) otherButtonTitles:nil] show];
}
}
else if (buttonIndex == 5)
{
MoreAppsVC * vc = [[MoreAppsVC alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}
}
- (void)sideToolbarDidUpdateShift:(SideToolbar *)toolbar

View file

@ -173,6 +173,8 @@ void InitLocalizedStrings()
[[Statistics instance] startSession];
[AppInfo sharedInfo]; // we call it to init -firstLaunchDate
if ([AppInfo sharedInfo].advertisingId)
[[Statistics instance] logEvent:@"Device Info" withParameters:@{@"IFA" : [AppInfo sharedInfo].advertisingId, @"Country" : [AppInfo sharedInfo].countryCode}];
InitLocalizedStrings();

View file

@ -0,0 +1,6 @@
#import <UIKit/UIKit.h>
@interface MoreAppsCell : UITableViewCell
@end

View file

@ -0,0 +1,6 @@
#import "MoreAppsCell.h"
@implementation MoreAppsCell
@end

View file

@ -0,0 +1,6 @@
#import <UIKit/UIKit.h>
@interface MoreAppsVC : UIViewController
@end

View file

@ -0,0 +1,214 @@
#import "MoreAppsVC.h"
#include "../../platform/platform.hpp"
#include "Framework.h"
#import "MoreAppsCell.h"
#import "UIKitCategories.h"
#import <iAd/iAd.h>
@interface MoreAppsVC () <UITableViewDataSource, UITableViewDelegate, ADBannerViewDelegate>
@property (nonatomic) UITableView * tableView;
@property (nonatomic) NSArray * guideRegions;
@property (nonatomic) NSArray * data;
@property (nonatomic) ADBannerView * bannerView;
@end
NSString * TitleMWM;
NSString * TitleGuides;
NSString * TitleAds;
using namespace::storage;
@implementation MoreAppsVC
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = NSLocalizedString(@"more_apps_title", nil);
guides::GuidesManager & manager = GetFramework().GetGuidesManager();
NSString * JSONPath = [NSString stringWithUTF8String:manager.GetDataFileFullPath().c_str()];
NSData * JSONData = [NSData dataWithContentsOfFile:JSONPath];
if (!JSONData)
{
JSONPath = [[NSBundle mainBundle] pathForResource:@"ios-guides" ofType:@"json"];
JSONData = [NSData dataWithContentsOfFile:JSONPath];
}
NSDictionary * JSON = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableContainers error:nil];
NSMutableArray * guideRegions = [[NSMutableArray alloc] init];
for (NSString * key in [JSON allKeys])
{
if ([key isEqualToString:@"version"])
continue;
NSDictionary * guide = JSON[key];
NSString * language = [[NSLocale preferredLanguages] firstObject];
NSString * message = guide[@"adMessages"][language];
if (!message)
message = guide[@"adMessages"][@"en"];
NSString * country = [[message componentsSeparatedByString:@":"] firstObject];
NSDictionary * info = @{@"Country" : country, @"URI" : guide[@"url"], @"GuideName" : key};
[guideRegions addObject:info];
}
self.guideRegions = [guideRegions sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"Country" ascending:YES]]];
TitleMWM = @"MapsWithMe Pro";
TitleGuides = NSLocalizedString(@"more_apps_guides", nil);
TitleAds = @"iAd";
[self updateData];
[self.view addSubview:self.tableView];
}
- (void)updateData
{
NSMutableArray * mData = [[NSMutableArray alloc] init];
if (!GetPlatform().IsPro())
[mData addObject:TitleMWM];
[mData addObject:TitleGuides];
if (self.bannerView.isBannerLoaded)
[mData addObject:TitleAds];
self.data = mData;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * title = self.data[indexPath.section];
if ([title isEqualToString:TitleMWM] || [title isEqualToString:TitleGuides])
{
MoreAppsCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (!cell)
cell = [[MoreAppsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
if ([title isEqualToString:TitleMWM])
{
cell.textLabel.text = TitleMWM;
cell.imageView.image = [UIImage imageNamed:@"MapsWithMeProIcon"];
}
else if ([title isEqualToString:TitleGuides])
{
NSDictionary * guide = self.guideRegions[indexPath.row];
cell.textLabel.text = guide[@"Country"];
cell.imageView.image = [UIImage imageNamed:guide[@"GuideName"]];
}
return cell;
}
else if ([title isEqualToString:TitleAds])
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"iAdCell"];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"iAdCell"];
self.bannerView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
self.bannerView.currentContentSizeIdentifier = UIDeviceOrientationIsPortrait(self.interfaceOrientation) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifierLandscape;
[cell.contentView addSubview:self.bannerView];
}
self.bannerView.midX = cell.width / 2;
return cell;
}
return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSString * title = self.data[indexPath.section];
if ([title isEqualToString:TitleMWM])
{
[[UIApplication sharedApplication] openProVersion];
}
else if ([title isEqualToString:TitleGuides])
{
NSDictionary * guide = self.guideRegions[indexPath.row];
[[UIApplication sharedApplication] openGuideWithName:guide[@"GuideName"] itunesURL:guide[@"URI"]];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSString * title = self.data[section];
if ([title isEqualToString:TitleMWM])
return 1;
else if ([title isEqualToString:TitleGuides])
return [self.guideRegions count];
else if ([title isEqualToString:TitleAds])
return 1;
return 0;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.data count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return self.data[section];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * title = self.data[indexPath.section];
if ([title isEqualToString:TitleMWM] || [title isEqualToString:TitleGuides])
return 44;
else
return self.bannerView.height;
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSInteger section = [self.data indexOfObject:TitleAds];
[self updateData];
if (section == NSNotFound)
{
section = [self.data indexOfObject:TitleAds];
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSInteger section = [self.data indexOfObject:TitleAds];
[self updateData];
if (section != NSNotFound)
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationAutomatic];
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
self.bannerView.currentContentSizeIdentifier = UIDeviceOrientationIsPortrait(self.interfaceOrientation) ? ADBannerContentSizeIdentifierPortrait : ADBannerContentSizeIdentifierLandscape;
[self updateData];
[self.tableView reloadData];
}
- (UITableView *)tableView
{
if (!_tableView)
{
_tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
_tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_tableView.dataSource = self;
_tableView.delegate = self;
}
return _tableView;
}
- (UIView *)bannerView
{
if (!_bannerView)
{
_bannerView = [[ADBannerView alloc] initWithFrame:CGRectZero];
_bannerView.delegate = self;
}
return _bannerView;
}
@end

View file

@ -40,15 +40,17 @@ typedef NS_ENUM(NSUInteger, Section)
NSLocalizedString(@"download_maps", nil),
NSLocalizedString(@"bookmarks", nil),
NSLocalizedString(@"settings", nil),
NSLocalizedString(@"share_my_location", nil)];
NSLocalizedString(@"share_my_location", nil),
NSLocalizedString(@"more_apps_title", nil)];
menuImageNames = @[@"IconSearch",
@"IconMap",
@"IconBookmarks",
@"IconSettings",
@"IconShare"];
@"IconShare",
@"IconMoreApps"];
disabledInTrial = @[@YES, @NO, @YES, @NO, @NO, @NO];
disabledInTrial = @[@YES, @NO, @YES, @NO, @NO, @NO, @NO];
self.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleLeftMargin;
[self addGestureRecognizer:self.menuPanGesture];

View file

@ -25,7 +25,6 @@
972CDCA318854AE5006641CA /* backButton.png in Resources */ = {isa = PBXBuildFile; fileRef = 972CDCA118854AE5006641CA /* backButton.png */; };
972CDCC41887EF9F006641CA /* SpeechKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 972CDCC31887EF9F006641CA /* SpeechKit.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
972CDCC61887F1B7006641CA /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 972CDCC51887F1B7006641CA /* CFNetwork.framework */; };
9735E6F918AA76C800CD16F2 /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97C98651186C5EF000AF7E9E /* iAd.framework */; };
97387546184E475000170BC4 /* MessageComposeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 97387545184E475000170BC4 /* MessageComposeViewController.m */; };
97387547184E475000170BC4 /* MessageComposeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 97387545184E475000170BC4 /* MessageComposeViewController.m */; };
9747264318323080006B7CB7 /* UIKitCategories.m in Sources */ = {isa = PBXBuildFile; fileRef = 9747264118323080006B7CB7 /* UIKitCategories.m */; };
@ -162,6 +161,9 @@
97D40C0F184E389000A1D572 /* MailComposeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 97D40C0D184E389000A1D572 /* MailComposeViewController.m */; };
97D807B818A92AAB00D416E0 /* MoreAppsVC.mm in Sources */ = {isa = PBXBuildFile; fileRef = 97D807B718A92AAB00D416E0 /* MoreAppsVC.mm */; };
97D807B918A92AAB00D416E0 /* MoreAppsVC.mm in Sources */ = {isa = PBXBuildFile; fileRef = 97D807B718A92AAB00D416E0 /* MoreAppsVC.mm */; };
97D807BC18A933FB00D416E0 /* MoreAppsCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 97D807BB18A933FB00D416E0 /* MoreAppsCell.m */; };
97D807BD18A933FB00D416E0 /* MoreAppsCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 97D807BB18A933FB00D416E0 /* MoreAppsCell.m */; };
97D807BE18A93C8800D416E0 /* iAd.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97C98651186C5EF000AF7E9E /* iAd.framework */; };
97DD585518A8EAFA0079837E /* libAarkiSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 97DD585218A8EAFA0079837E /* libAarkiSDK.a */; };
97DD585618A8EAFB0079837E /* libAarkiSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 97DD585218A8EAFA0079837E /* libAarkiSDK.a */; };
97DD585818A8EB060079837E /* MobileAppTracker.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 97DD585718A8EB060079837E /* MobileAppTracker.framework */; };
@ -1658,6 +1660,8 @@
97D40C0D184E389000A1D572 /* MailComposeViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MailComposeViewController.m; sourceTree = "<group>"; };
97D807B618A92AAB00D416E0 /* MoreAppsVC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MoreAppsVC.h; sourceTree = "<group>"; };
97D807B718A92AAB00D416E0 /* MoreAppsVC.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MoreAppsVC.mm; sourceTree = "<group>"; };
97D807BA18A933FB00D416E0 /* MoreAppsCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MoreAppsCell.h; sourceTree = "<group>"; };
97D807BB18A933FB00D416E0 /* MoreAppsCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MoreAppsCell.m; sourceTree = "<group>"; };
97DD585218A8EAFA0079837E /* libAarkiSDK.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libAarkiSDK.a; sourceTree = "<group>"; };
97DD585318A8EAFA0079837E /* Aarki.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Aarki.h; sourceTree = "<group>"; };
97DD585418A8EAFA0079837E /* AarkiContact.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AarkiContact.h; sourceTree = "<group>"; };
@ -2347,7 +2351,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9735E6F918AA76C800CD16F2 /* iAd.framework in Frameworks */,
97D807BE18A93C8800D416E0 /* iAd.framework in Frameworks */,
97719D491843B6F700BDD815 /* Security.framework in Frameworks */,
97719D451843B6DC00BDD815 /* MessageUI.framework in Frameworks */,
97ECD87F1836594400F77A46 /* StoreKit.framework in Frameworks */,
@ -2451,8 +2455,7 @@
children = (
97B4E9271851DAB300BEC5D7 /* Custom Views */,
9789DB53188D5DFF007C6FAE /* In App Messaging */,
97D807B618A92AAB00D416E0 /* MoreAppsVC.h */,
97D807B718A92AAB00D416E0 /* MoreAppsVC.mm */,
9770A04618AD19D300126E5C /* More Apps */,
978F9251183BD530000D6C7C /* NavigationController.h */,
978F9252183BD530000D6C7C /* NavigationController.mm */,
97D40C0C184E389000A1D572 /* MailComposeViewController.h */,
@ -2616,6 +2619,17 @@
path = SideToolbar;
sourceTree = "<group>";
};
9770A04618AD19D300126E5C /* More Apps */ = {
isa = PBXGroup;
children = (
97D807B618A92AAB00D416E0 /* MoreAppsVC.h */,
97D807B718A92AAB00D416E0 /* MoreAppsVC.mm */,
97D807BA18A933FB00D416E0 /* MoreAppsCell.h */,
97D807BB18A933FB00D416E0 /* MoreAppsCell.m */,
);
name = "More Apps";
sourceTree = "<group>";
};
9789DB53188D5DFF007C6FAE /* In App Messaging */ = {
isa = PBXGroup;
children = (
@ -5034,6 +5048,7 @@
FAA5C2A2144F135F005337F6 /* LocationManager.mm in Sources */,
FA81AE3314D061BF00A0D70D /* SearchCell.mm in Sources */,
978F9240183B660F000D6C7C /* SettingsViewController.mm in Sources */,
97D807BC18A933FB00D416E0 /* MoreAppsCell.m in Sources */,
F7B90CD31521E6D200C054EE /* CustomNavigationView.mm in Sources */,
FA36B80D15403A4F004560CC /* BookmarksVC.mm in Sources */,
FA5D4F191557F79900E7D8BB /* PlacePageVC.mm in Sources */,
@ -5111,6 +5126,7 @@
97719D431843AF1E00BDD815 /* ScopeView.m in Sources */,
FAFB08F4151215EE0041901D /* CompassView.mm in Sources */,
FAFB08F5151215EE0041901D /* Preferences.mm in Sources */,
97D807BD18A933FB00D416E0 /* MoreAppsCell.m in Sources */,
FAFB08F6151215EE0041901D /* LocationManager.mm in Sources */,
97C9860D186C487900AF7E9E /* MPAdAlertGestureRecognizer.m in Sources */,
97C98641186C487900AF7E9E /* MPBannerCustomEvent.m in Sources */,

View file

@ -70,9 +70,5 @@
<string>***REMOVED***</string>
<key>MobileAppTrackerAdvertiserId</key>
<string>14130</string>
<key>MoPubInterstitialAdUnitId</key>
<string>6ca53c8a5bbf497dbc24b4f5ff6addef</string>
<key>MoPubTopBannerAdUnitId</key>
<string>78b52bc1fc0e4931bb05f34fd3df7ea9</string>
</dict>
</plist>