40
40
#import " OfflineTableViewController.h"
41
41
#import " SettingsTableViewController.h"
42
42
#import " SecurityOptionsTableViewController.h"
43
+ #import " ContactRequestsViewController.h"
43
44
44
45
#import " BrowserViewController.h"
45
46
#import " MEGAStore.h"
46
47
#import " MEGAPurchase.h"
47
48
48
- #import < ifaddrs.h>
49
- #import < arpa/inet.h>
50
49
#import < Crashlytics/Crashlytics.h>
51
50
#import < Fabric/Fabric.h>
52
51
#import < QuickLook/QuickLook.h>
@@ -66,7 +65,8 @@ typedef NS_ENUM(NSUInteger, URLType) {
66
65
URLTypeConfirmationLink,
67
66
URLTypeOpenInLink,
68
67
URLTypeNewSignUpLink,
69
- URLTypeBackupLink
68
+ URLTypeBackupLink,
69
+ URLTypeIncomingPendingContactsLink
70
70
};
71
71
72
72
@interface AppDelegate () <UIAlertViewDelegate, LTHPasscodeViewControllerDelegate> {
@@ -83,12 +83,12 @@ @interface AppDelegate () <UIAlertViewDelegate, LTHPasscodeViewControllerDelegat
83
83
NSTimer *timerAPI_EAGAIN;
84
84
}
85
85
86
- @property (nonatomic , strong ) NSString *IpAddress;
87
-
88
86
@property (nonatomic , strong ) NSURL *link;
89
87
@property (nonatomic ) URLType urlType;
90
88
@property (nonatomic , strong ) NSString *emailOfNewSignUpLink;
91
89
90
+ @property (nonatomic , strong ) UIAlertView *API_ESIDAlertView;
91
+
92
92
@property (nonatomic , weak ) MainTabBarController *mainTBC;
93
93
94
94
@end
@@ -106,11 +106,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
106
106
[[AVAudioSession sharedInstance ] setCategory: AVAudioSessionCategoryPlayback error: nil ];
107
107
[[AVAudioSession sharedInstance ] setActive: NO withOptions: AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error: nil ];
108
108
109
- self.IpAddress = [self getIpAddress ];
110
109
[MEGAReachabilityManager sharedManager ];
111
110
112
- [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (reachabilityDidChange: ) name: kReachabilityChangedNotification object: nil ];
113
-
114
111
[UIDevice currentDevice ].batteryMonitoringEnabled = YES ;
115
112
[[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (batteryChanged: ) name: UIDeviceBatteryStateDidChangeNotification object: nil ];
116
113
@@ -524,6 +521,11 @@ - (void)processLink:(NSURL *)url {
524
521
return ;
525
522
}
526
523
524
+ if ([self isIncomingPendingContactsLink: afterSlashesString]) {
525
+ self.urlType = URLTypeIncomingPendingContactsLink;
526
+ return ;
527
+ }
528
+
527
529
[self showLinkNotValid ];
528
530
}
529
531
@@ -657,6 +659,33 @@ - (BOOL)isBackupLink:(NSString *)afterSlashesString {
657
659
return NO ;
658
660
}
659
661
662
+ - (BOOL )isIncomingPendingContactsLink : (NSString *)afterSlashesString {
663
+ if (afterSlashesString.length < 6 ) {
664
+ return NO ;
665
+ }
666
+
667
+ BOOL isIncomingPendingContactsLink = [[afterSlashesString substringToIndex: 7 ] isEqualToString: @" #fm/ipc" ]; // mega://"#fm/ipc"
668
+ if (isIncomingPendingContactsLink) {
669
+ if ([SSKeychain passwordForService: @" MEGA" account: @" sessionV3" ]) {
670
+ ContactRequestsViewController *contactsRequestsVC = [[UIStoryboard storyboardWithName: @" Contacts" bundle: nil ] instantiateViewControllerWithIdentifier: @" ContactsRequestsViewControllerID" ];
671
+ UIBarButtonItem *cancelBarButtonItem = [[UIBarButtonItem alloc ] initWithImage: [UIImage imageNamed: @" cancelIcon" ] style: UIBarButtonItemStylePlain target: nil action: @selector (dismissPresentedViews )];
672
+ [contactsRequestsVC.navigationItem setLeftBarButtonItem: cancelBarButtonItem];
673
+ MEGANavigationController *navigationController = [[MEGANavigationController alloc ] initWithRootViewController: contactsRequestsVC];
674
+ [self presentLinkViewController: navigationController];
675
+ } else {
676
+ UIAlertView *alert = [[UIAlertView alloc ] initWithTitle: AMLocalizedString (@" pleaseLogInToYourAccount" , nil )
677
+ message: nil
678
+ delegate: self
679
+ cancelButtonTitle: AMLocalizedString (@" ok" , nil )
680
+ otherButtonTitles: nil ];
681
+ [alert show ];
682
+ }
683
+ return YES ;
684
+ }
685
+
686
+ return NO ;
687
+ }
688
+
660
689
- (void )openIn {
661
690
if ([SSKeychain passwordForService: @" MEGA" account: @" sessionV3" ]) {
662
691
MEGANavigationController *browserNavigationController = [[UIStoryboard storyboardWithName: @" Cloud" bundle: nil ] instantiateViewControllerWithIdentifier: @" BrowserNavigationControllerID" ];
@@ -767,76 +796,6 @@ - (UIBarButtonItem *)cancelBarButtonItem {
767
796
return cancelBarButtonItem;
768
797
}
769
798
770
- #pragma mark - Get IP Address
771
-
772
- - (NSString *)getIpAddress {
773
- NSString *address = nil ;
774
-
775
- struct ifaddrs *interfaces = NULL ;
776
- struct ifaddrs *temp_addr = NULL ;
777
-
778
- int success = 0 ;
779
- success = getifaddrs (&interfaces);
780
- if (success == 0 ) {
781
-
782
- temp_addr = interfaces;
783
- while (temp_addr != NULL ) {
784
- if (temp_addr->ifa_addr ->sa_family == AF_INET) {
785
- if ([[NSString stringWithUTF8String: temp_addr->ifa_name] isEqualToString: @" en0" ] || [[NSString stringWithUTF8String: temp_addr->ifa_name] isEqualToString: @" pdp_ip0" ]) {
786
- char straddr[INET_ADDRSTRLEN];
787
- inet_ntop (AF_INET, (void *)&((struct sockaddr_in *)temp_addr->ifa_addr )->sin_addr , straddr, sizeof (straddr));
788
-
789
- if (strncasecmp (straddr, " 127." , 4 ) && strncasecmp (straddr, " 169.254." , 8 )) {
790
- address = [NSString stringWithUTF8String: straddr];
791
- }
792
- }
793
- }
794
-
795
- if (temp_addr->ifa_addr ->sa_family == AF_INET6) {
796
- if ([[NSString stringWithUTF8String: temp_addr->ifa_name] isEqualToString: @" en0" ] || [[NSString stringWithUTF8String: temp_addr->ifa_name] isEqualToString: @" pdp_ip0" ]) {
797
- char straddr[INET6_ADDRSTRLEN];
798
- inet_ntop (AF_INET6, (void *)&((struct sockaddr_in *)temp_addr->ifa_addr )->sin_addr , straddr, sizeof (straddr));
799
-
800
- if (strncasecmp (straddr, " FE80:" , 5 ) && strncasecmp (straddr, " FD00:" , 5 )) {
801
- address = [NSString stringWithUTF8String: straddr];
802
- }
803
- }
804
- }
805
-
806
- temp_addr = temp_addr->ifa_next ;
807
- }
808
- }
809
-
810
- freeifaddrs (interfaces);
811
-
812
- return address;
813
- }
814
-
815
- #pragma mark - Reachability Changes
816
-
817
- - (void )reachabilityDidChange : (NSNotification *)notification {
818
-
819
- if ([MEGAReachabilityManager isReachable ]) {
820
- NSString *currentIP = [self getIpAddress ];
821
- if (![self .IpAddress isEqualToString: currentIP]) {
822
- [[MEGASdkManager sharedMEGASdk ] reconnect ];
823
- self.IpAddress = currentIP;
824
- }
825
- }
826
-
827
- if ([[CameraUploads syncManager ] isCameraUploadsEnabled ]) {
828
- if (![[CameraUploads syncManager ] isUseCellularConnectionEnabled ]) {
829
- if ([MEGAReachabilityManager isReachableViaWWAN ]) {
830
- [[CameraUploads syncManager ] resetOperationQueue ];
831
- }
832
-
833
- if ([[MEGASdkManager sharedMEGASdk ] isLoggedIn ] && [MEGAReachabilityManager isReachableViaWiFi ]) {
834
- [[CameraUploads syncManager ] setIsCameraUploadsEnabled: YES ];
835
- }
836
- }
837
- }
838
- }
839
-
840
799
#pragma mark - Battery changed
841
800
842
801
- (void )batteryChanged : (NSNotification *)notification {
@@ -1108,9 +1067,13 @@ - (void)onRequestFinish:(MEGASdk *)api request:(MEGARequest *)request error:(MEG
1108
1067
}
1109
1068
1110
1069
case MEGAErrorTypeApiESid: {
1111
- UIAlertView *alertView = [[UIAlertView alloc ] initWithTitle: AMLocalizedString (@" loggedOut_alertTitle" , nil ) message: AMLocalizedString (@" loggedOutFromAnotherLocation" , nil ) delegate: nil cancelButtonTitle: @" Ok" otherButtonTitles: nil , nil ];
1112
- [alertView show ];
1113
- [Helper logout ];
1070
+ if ([request type ] == MEGARequestTypeLogin || [request type ] == MEGARequestTypeLogout) {
1071
+ if (![_API_ESIDAlertView isVisible ]) {
1072
+ _API_ESIDAlertView = [[UIAlertView alloc ] initWithTitle: AMLocalizedString (@" loggedOut_alertTitle" , nil ) message: AMLocalizedString (@" loggedOutFromAnotherLocation" , nil ) delegate: nil cancelButtonTitle: AMLocalizedString (@" ok" , nil ) otherButtonTitles: nil , nil ];
1073
+ [_API_ESIDAlertView show ];
1074
+ [Helper logout ];
1075
+ }
1076
+ }
1114
1077
break ;
1115
1078
}
1116
1079
@@ -1120,9 +1083,12 @@ - (void)onRequestFinish:(MEGASdk *)api request:(MEGARequest *)request error:(MEG
1120
1083
}
1121
1084
1122
1085
case MEGAErrorTypeApiESSL: {
1123
- UIAlertView *alertView = [[UIAlertView alloc ] initWithTitle: AMLocalizedString (@" sslUnverified_alertTitle" , nil ) message: nil delegate: nil cancelButtonTitle: AMLocalizedString (@" ok" , nil ) otherButtonTitles: nil , nil ];
1124
- [alertView show ];
1125
- [Helper logout ];
1086
+ if ([request type ] == MEGARequestTypeLogout) {
1087
+ NSString *issuer = [NSString stringWithFormat: @" (Issuer: %@ )" , [request text ] ? [request text ] : @" Unknown" ];
1088
+ UIAlertView *alertView = [[UIAlertView alloc ] initWithTitle: AMLocalizedString (@" sslUnverified_alertTitle" , nil ) message: issuer delegate: nil cancelButtonTitle: AMLocalizedString (@" ok" , nil ) otherButtonTitles: nil , nil ];
1089
+ [alertView show ];
1090
+ [Helper logout ];
1091
+ }
1126
1092
break ;
1127
1093
}
1128
1094
@@ -1353,31 +1319,10 @@ - (void)onTransferUpdate:(MEGASdk *)api transfer:(MEGATransfer *)transfer {
1353
1319
}
1354
1320
1355
1321
- (void )onTransferFinish : (MEGASdk *)api transfer : (MEGATransfer *)transfer error : (MEGAError *)error {
1356
- if ([error type ]) {
1357
- switch ([error type ]) {
1358
- case MEGAErrorTypeApiEOverQuota: {
1359
- [self showOverquotaAlert ];
1360
- break ;
1361
- }
1362
-
1363
- default :
1364
- break ;
1365
- }
1366
- return ;
1367
- }
1368
-
1369
1322
if (transfer.isStreamingTransfer ) {
1370
1323
return ;
1371
1324
}
1372
1325
1373
- // Delete local file even if we get an error
1374
- if ([transfer type ] == MEGATransferTypeUpload) {
1375
- NSError *error = nil ;
1376
- if (![[NSFileManager defaultManager ] removeItemAtPath: transfer.path error: &error]) {
1377
- MEGALogError (@" Remove item at path: %@ " , error)
1378
- }
1379
- }
1380
-
1381
1326
// Delete transfer from dictionary file even if we get an error
1382
1327
MEGANode *node = nil ;
1383
1328
if ([transfer type ] == MEGATransferTypeDownload) {
@@ -1388,9 +1333,23 @@ - (void)onTransferFinish:(MEGASdk *)api transfer:(MEGATransfer *)transfer error:
1388
1333
if (node) {
1389
1334
[[Helper downloadingNodes ] removeObjectForKey: node.base64Handle];
1390
1335
}
1336
+ } else if ([transfer type ] == MEGATransferTypeUpload) {
1337
+ NSError *error = nil ;
1338
+ if (![[NSFileManager defaultManager ] removeItemAtPath: transfer.path error: &error]) {
1339
+ MEGALogError (@" Remove item at path: %@ " , error)
1340
+ }
1391
1341
}
1392
1342
1393
1343
if ([error type ]) {
1344
+ switch ([error type ]) {
1345
+ case MEGAErrorTypeApiEOverQuota: {
1346
+ [self showOverquotaAlert ];
1347
+ break ;
1348
+ }
1349
+
1350
+ default :
1351
+ break ;
1352
+ }
1394
1353
return ;
1395
1354
}
1396
1355
@@ -1446,9 +1405,7 @@ - (void)onTransferFinish:(MEGASdk *)api transfer:(MEGATransfer *)transfer error:
1446
1405
1447
1406
[[NSFileManager defaultManager ] removeItemAtPath: tmpImagePath error: nil ];
1448
1407
}
1449
- }
1450
-
1451
- if ([transfer type ] == MEGATransferTypeUpload) {
1408
+ } else if ([transfer type ] == MEGATransferTypeUpload) {
1452
1409
if (isImage ([transfer fileName ].pathExtension )) {
1453
1410
MEGANode *node = [api nodeForHandle: transfer.nodeHandle];
1454
1411
[api createThumbnail: transfer.path destinatioPath: [Helper pathForNode: node searchPath: NSCachesDirectory directory: @" thumbnailsV3" ]];
0 commit comments