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

MWMHelpController.mm « Maps « iphone - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5ba66f439517a45b6476ee15025d205076049d3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#import "MWMHelpController.h"
#import <sys/utsname.h>
#import "AppInfo.h"
#import "Common.h"
#import "MWMMailViewController.h"
#import "Statistics.h"
#import "UIColor+MapsMeColor.h"
#import "WebViewController.h"

#import "3party/Alohalytics/src/alohalytics_objc.h"

#include "platform/platform.hpp"

extern NSString * const kAlohalyticsTapEventKey;
extern NSString * const kLocaleUsedInSupportEmails = @"en_gb";
extern NSDictionary * const kDeviceNames = @{
  @"i386" : @"Simulator",
  @"iPad1,1" : @"iPad WiFi",
  @"iPad1,2" : @"iPad GSM",
  @"iPad2,1" : @"iPad 2 WiFi",
  @"iPad2,2" : @"iPad 2 CDMA",
  @"iPad2,2" : @"iPad 2 GSM",
  @"iPad2,3" : @"iPad 2 GSM EV-DO",
  @"iPad2,4" : @"iPad 2",
  @"iPad2,5" : @"iPad Mini WiFi",
  @"iPad2,6" : @"iPad Mini GSM",
  @"iPad2,7" : @"iPad Mini CDMA",
  @"iPad3,1" : @"iPad 3rd gen. WiFi",
  @"iPad3,2" : @"iPad 3rd gen. GSM",
  @"iPad3,3" : @"iPad 3rd gen. CDMA",
  @"iPad3,4" : @"iPad 4th gen. WiFi",
  @"iPad3,5" : @"iPad 4th gen. GSM",
  @"iPad3,6" : @"iPad 4th gen. CDMA",
  @"iPad4,1" : @"iPad Air WiFi",
  @"iPad4,2" : @"iPad Air GSM",
  @"iPad4,3" : @"iPad Air CDMA",
  @"iPad4,4" : @"iPad Mini 2nd gen. WiFi",
  @"iPad4,5" : @"iPad Mini 2nd gen. GSM",
  @"iPad4,6" : @"iPad Mini 2nd gen. CDMA",
  @"iPad5,3" : @"iPad Air 2 WiFi",
  @"iPad5,4" : @"iPad Air 2 GSM",
  @"iPad6,3" : @"iPad Pro (9.7 inch) WiFi",
  @"iPad6,4" : @"iPad Pro (9.7 inch) GSM",
  @"iPad6,7" : @"iPad Pro (12.9 inch) WiFi",
  @"iPad6,8" : @"iPad Pro (12.9 inch) GSM",
  @"iPhone1,1" : @"iPhone",
  @"iPhone1,2" : @"iPhone 3G",
  @"iPhone2,1" : @"iPhone 3GS",
  @"iPhone3,1" : @"iPhone 4 GSM",
  @"iPhone3,2" : @"iPhone 4 CDMA",
  @"iPhone3,3" : @"iPhone 4 GSM EV-DO",
  @"iPhone4,1" : @"iPhone 4S",
  @"iPhone4,2" : @"iPhone 4S",
  @"iPhone4,3" : @"iPhone 4S",
  @"iPhone5,1" : @"iPhone 5",
  @"iPhone5,2" : @"iPhone 5",
  @"iPhone5,3" : @"iPhone 5c",
  @"iPhone5,4" : @"iPhone 5c",
  @"iPhone6,1" : @"iPhone 5s",
  @"iPhone6,2" : @"iPhone 5s",
  @"iPhone7,1" : @"iPhone 6 Plus",
  @"iPhone7,2" : @"iPhone 6",
  @"iPhone8,1" : @"iPhone 6s",
  @"iPhone8,2" : @"iPhone 6s Plus",
  @"iPhone8,4" : @"iPhone SE",
  @"iPod1,1" : @"iPod Touch",
  @"iPod2,1" : @"iPod Touch 2nd gen.",
  @"iPod3,1" : @"iPod Touch 3rd gen.",
  @"iPod4,1" : @"iPod Touch 4th gen.",
  @"iPod5,1" : @"iPod Touch 5th gen.",
  @"x86_64" : @"Simulator",
};

namespace
{
NSString * const kCommonReportActionTitle = L(@"leave_a_review");
NSString * const kBugReportActionTitle = L(@"something_is_not_working");
NSString * const kCancelActionTitle = L(@"cancel");
NSString * const kiOSEmail = @"ios@maps.me";
}

@interface MWMHelpController ()<MFMailComposeViewControllerDelegate>

@property(nonatomic) WebViewController * aboutViewController;

@property(weak, nonatomic) IBOutlet UIView * separatorView;

@end  // namespace

@implementation MWMHelpController

- (void)viewDidLoad
{
  [super viewDidLoad];

  self.title = L(@"help");

  NSString * html;
  if (GetPlatform().ConnectionStatus() == Platform::EConnectionType::CONNECTION_NONE)
  {
    NSString * path = [[NSBundle mainBundle] pathForResource:@"faq" ofType:@"html"];
    html = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
    self.aboutViewController =
        [[WebViewController alloc] initWithHtml:html baseUrl:nil andTitleOrNil:nil];
  }
  else
  {
    NSURL * url = [NSURL URLWithString:@"https://support.maps.me"];
    self.aboutViewController = [[WebViewController alloc] initWithUrl:url andTitleOrNil:nil];
  }

  self.aboutViewController.openInSafari = NO;
  UIView * aboutView = self.aboutViewController.view;
  [self addChildViewController:self.aboutViewController];
  [self.view addSubview:aboutView];

  aboutView.translatesAutoresizingMaskIntoConstraints = NO;
  NSLayoutConstraint * top = [NSLayoutConstraint constraintWithItem:self.view
                                                          attribute:NSLayoutAttributeTop
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:aboutView
                                                          attribute:NSLayoutAttributeTop
                                                         multiplier:1.0
                                                           constant:0.0];
  NSLayoutConstraint * bottom = [NSLayoutConstraint constraintWithItem:self.separatorView
                                                             attribute:NSLayoutAttributeTop
                                                             relatedBy:NSLayoutRelationEqual
                                                                toItem:aboutView
                                                             attribute:NSLayoutAttributeBottom
                                                            multiplier:1.0
                                                              constant:0.0];
  NSLayoutConstraint * left = [NSLayoutConstraint constraintWithItem:self.view
                                                           attribute:NSLayoutAttributeLeft
                                                           relatedBy:NSLayoutRelationEqual
                                                              toItem:aboutView
                                                           attribute:NSLayoutAttributeLeft
                                                          multiplier:1.0
                                                            constant:0.0];
  NSLayoutConstraint * right = [NSLayoutConstraint constraintWithItem:self.view
                                                            attribute:NSLayoutAttributeRight
                                                            relatedBy:NSLayoutRelationEqual
                                                               toItem:aboutView
                                                            attribute:NSLayoutAttributeRight
                                                           multiplier:1.0
                                                             constant:0.0];

  [self.view addConstraints:@[ top, bottom, left, right ]];
}

- (IBAction)reportBug
{
  UIAlertController * alert =
      [UIAlertController alertControllerWithTitle:L(@"feedback")
                                          message:nil
                                   preferredStyle:UIAlertControllerStyleAlert];

  UIAlertAction * commonReport = [UIAlertAction actionWithTitle:kCommonReportActionTitle
                                                          style:UIAlertActionStyleDefault
                                                        handler:^(UIAlertAction * _Nonnull action) {
                                                          [self commonReportAction];
                                                        }];
  [alert addAction:commonReport];

  UIAlertAction * bugReport = [UIAlertAction actionWithTitle:kBugReportActionTitle
                                                       style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction * _Nonnull action) {
                                                       [self bugReportAction];
                                                     }];
  [alert addAction:bugReport];

  UIAlertAction * cancel =
      [UIAlertAction actionWithTitle:kCancelActionTitle style:UIAlertActionStyleCancel handler:nil];
  [alert addAction:cancel];
  alert.preferredAction = cancel;

  [self presentViewController:alert animated:YES completion:nil];
}

#pragma mark - Actions

- (void)commonReportAction
{
  [Statistics logEvent:kStatSettingsOpenSection withParameters:@{kStatName : kStatFeedback}];
  [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"contactUs"];
  // Do not localize subject. Support team uses it to filter emails.
  [self sendEmailWithSubject:@"Feedback from user" toRecipient:kiOSEmail];
}

- (void)bugReportAction
{
  [Statistics logEvent:kStatSettingsOpenSection withParameters:@{kStatName : kStatReport}];
  [Alohalytics logEvent:kAlohalyticsTapEventKey withValue:@"reportABug"];
  // Do not localize subject. Support team uses it to filter emails.
  [self sendEmailWithSubject:@"Bug report from user" toRecipient:kiOSEmail];
}

#pragma mark - Email

- (void)sendEmailWithSubject:(NSString *)subject toRecipient:(NSString *)email
{
  if ([MWMMailViewController canSendMail])
  {
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString * machine =
        [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    NSString * device = kDeviceNames[machine];
    if (!device)
      device = machine;
    NSString * languageCode = [[NSLocale preferredLanguages] firstObject];
    NSString * language = [[NSLocale localeWithLocaleIdentifier:kLocaleUsedInSupportEmails]
        displayNameForKey:NSLocaleLanguageCode
                    value:languageCode];
    NSString * locale = [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode];
    NSString * country = [[NSLocale localeWithLocaleIdentifier:kLocaleUsedInSupportEmails]
        displayNameForKey:NSLocaleCountryCode
                    value:locale];
    NSString * bundleVersion =
        [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
    NSString * text = [NSString stringWithFormat:@"\n\n\n\n- %@ (%@)\n- MAPS.ME %@\n- %@/%@",
                                                 device, [UIDevice currentDevice].systemVersion,
                                                 bundleVersion, language, country];
    NSString * alohalyticsId = [Alohalytics installationId];
    if (alohalyticsId)
      text = [NSString stringWithFormat:@"%@\n- %@", text, alohalyticsId];

    MWMMailViewController * vc = [[MWMMailViewController alloc] init];
    vc.mailComposeDelegate = self;
    [vc setSubject:[NSString stringWithFormat:@"[%@ iOS] %@", [AppInfo sharedInfo].bundleVersion,
                                              subject]];
    [vc setMessageBody:text isHTML:NO];
    [vc setToRecipients:@[ email ]];
    [vc.navigationBar setTintColor:[UIColor whitePrimaryText]];
    [self presentViewController:vc animated:YES completion:nil];
  }
  else
  {
    NSString * text = [NSString stringWithFormat:L(@"email_error_body"), email];
    [[[UIAlertView alloc] initWithTitle:L(@"email_error_title")
                                message:text
                               delegate:nil
                      cancelButtonTitle:L(@"ok")
                      otherButtonTitles:nil] show];
  }
}

- (void)mailComposeController:(MFMailComposeViewController *)controller
          didFinishWithResult:(MFMailComposeResult)result
                        error:(NSError *)error
{
  [self dismissViewControllerAnimated:YES completion:nil];
}

@end