4040#import " OfflineTableViewController.h"
4141#import " SettingsTableViewController.h"
4242#import " SecurityOptionsTableViewController.h"
43+ #import " ContactRequestsViewController.h"
4344
4445#import " BrowserViewController.h"
4546#import " MEGAStore.h"
4647#import " MEGAPurchase.h"
4748
48- #import < ifaddrs.h>
49- #import < arpa/inet.h>
5049#import < Crashlytics/Crashlytics.h>
5150#import < Fabric/Fabric.h>
5251#import < QuickLook/QuickLook.h>
@@ -66,7 +65,8 @@ typedef NS_ENUM(NSUInteger, URLType) {
6665 URLTypeConfirmationLink,
6766 URLTypeOpenInLink,
6867 URLTypeNewSignUpLink,
69- URLTypeBackupLink
68+ URLTypeBackupLink,
69+ URLTypeIncomingPendingContactsLink
7070};
7171
7272@interface AppDelegate () <UIAlertViewDelegate, LTHPasscodeViewControllerDelegate> {
@@ -83,12 +83,12 @@ @interface AppDelegate () <UIAlertViewDelegate, LTHPasscodeViewControllerDelegat
8383 NSTimer *timerAPI_EAGAIN;
8484}
8585
86- @property (nonatomic , strong ) NSString *IpAddress;
87-
8886@property (nonatomic , strong ) NSURL *link;
8987@property (nonatomic ) URLType urlType;
9088@property (nonatomic , strong ) NSString *emailOfNewSignUpLink;
9189
90+ @property (nonatomic , strong ) UIAlertView *API_ESIDAlertView;
91+
9292@property (nonatomic , weak ) MainTabBarController *mainTBC;
9393
9494@end
@@ -106,11 +106,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
106106 [[AVAudioSession sharedInstance ] setCategory: AVAudioSessionCategoryPlayback error: nil ];
107107 [[AVAudioSession sharedInstance ] setActive: NO withOptions: AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error: nil ];
108108
109- self.IpAddress = [self getIpAddress ];
110109 [MEGAReachabilityManager sharedManager ];
111110
112- [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (reachabilityDidChange: ) name: kReachabilityChangedNotification object: nil ];
113-
114111 [UIDevice currentDevice ].batteryMonitoringEnabled = YES ;
115112 [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (batteryChanged: ) name: UIDeviceBatteryStateDidChangeNotification object: nil ];
116113
@@ -524,6 +521,11 @@ - (void)processLink:(NSURL *)url {
524521 return ;
525522 }
526523
524+ if ([self isIncomingPendingContactsLink: afterSlashesString]) {
525+ self.urlType = URLTypeIncomingPendingContactsLink;
526+ return ;
527+ }
528+
527529 [self showLinkNotValid ];
528530}
529531
@@ -657,6 +659,33 @@ - (BOOL)isBackupLink:(NSString *)afterSlashesString {
657659 return NO ;
658660}
659661
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+
660689- (void )openIn {
661690 if ([SSKeychain passwordForService: @" MEGA" account: @" sessionV3" ]) {
662691 MEGANavigationController *browserNavigationController = [[UIStoryboard storyboardWithName: @" Cloud" bundle: nil ] instantiateViewControllerWithIdentifier: @" BrowserNavigationControllerID" ];
@@ -767,76 +796,6 @@ - (UIBarButtonItem *)cancelBarButtonItem {
767796 return cancelBarButtonItem;
768797}
769798
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-
840799#pragma mark - Battery changed
841800
842801- (void )batteryChanged : (NSNotification *)notification {
@@ -1108,9 +1067,13 @@ - (void)onRequestFinish:(MEGASdk *)api request:(MEGARequest *)request error:(MEG
11081067 }
11091068
11101069 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+ }
11141077 break ;
11151078 }
11161079
@@ -1120,9 +1083,12 @@ - (void)onRequestFinish:(MEGASdk *)api request:(MEGARequest *)request error:(MEG
11201083 }
11211084
11221085 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+ }
11261092 break ;
11271093 }
11281094
@@ -1353,31 +1319,10 @@ - (void)onTransferUpdate:(MEGASdk *)api transfer:(MEGATransfer *)transfer {
13531319}
13541320
13551321- (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-
13691322 if (transfer.isStreamingTransfer ) {
13701323 return ;
13711324 }
13721325
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-
13811326 // Delete transfer from dictionary file even if we get an error
13821327 MEGANode *node = nil ;
13831328 if ([transfer type ] == MEGATransferTypeDownload) {
@@ -1388,9 +1333,23 @@ - (void)onTransferFinish:(MEGASdk *)api transfer:(MEGATransfer *)transfer error:
13881333 if (node) {
13891334 [[Helper downloadingNodes ] removeObjectForKey: node.base64Handle];
13901335 }
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+ }
13911341 }
13921342
13931343 if ([error type ]) {
1344+ switch ([error type ]) {
1345+ case MEGAErrorTypeApiEOverQuota: {
1346+ [self showOverquotaAlert ];
1347+ break ;
1348+ }
1349+
1350+ default :
1351+ break ;
1352+ }
13941353 return ;
13951354 }
13961355
@@ -1446,9 +1405,7 @@ - (void)onTransferFinish:(MEGASdk *)api transfer:(MEGATransfer *)transfer error:
14461405
14471406 [[NSFileManager defaultManager ] removeItemAtPath: tmpImagePath error: nil ];
14481407 }
1449- }
1450-
1451- if ([transfer type ] == MEGATransferTypeUpload) {
1408+ } else if ([transfer type ] == MEGATransferTypeUpload) {
14521409 if (isImage ([transfer fileName ].pathExtension )) {
14531410 MEGANode *node = [api nodeForHandle: transfer.nodeHandle];
14541411 [api createThumbnail: transfer.path destinatioPath: [Helper pathForNode: node searchPath: NSCachesDirectory directory: @" thumbnailsV3" ]];
0 commit comments