From 7ea78c895268197a555180c12db28acc78b9de6c Mon Sep 17 00:00:00 2001 From: Benjamin Verdier Date: Tue, 19 Jun 2018 15:45:16 +0200 Subject: [PATCH] add support of qrcode reading for provisioning profile [Switch submodule branch] --- .gitmodules | 3 + Classes/AssistantView.h | 4 ++ Classes/AssistantView.m | 76 ++++++++++++++++++++- Classes/Base.lproj/AssistantViewScreens.xib | 12 +++- Classes/LinphoneAppDelegate.h | 1 + Classes/LinphoneAppDelegate.m | 23 ++----- Classes/LinphoneManager.h | 1 + Classes/LinphoneManager.m | 8 +++ submodules/cmake-builder | 2 +- submodules/externals/zxing-cpp | 1 + 10 files changed, 107 insertions(+), 24 deletions(-) create mode 160000 submodules/externals/zxing-cpp diff --git a/.gitmodules b/.gitmodules index c0b3e8588..fafbc42bc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -117,3 +117,6 @@ [submodule "submodules/externals/soci"] path = submodules/externals/soci url = git://git.linphone.org/soci +[submodule "submodules/externals/zxing-cpp"] + path = submodules/externals/zxing-cpp + url = git://git.linphone.org/zxing-cpp.git diff --git a/Classes/AssistantView.h b/Classes/AssistantView.h index 3184f85bc..815174526 100644 --- a/Classes/AssistantView.h +++ b/Classes/AssistantView.h @@ -21,6 +21,7 @@ #import "UICompositeView.h" #import "TPKeyboardAvoidingScrollView.h" #import "PhoneMainView.h" +#import @interface AssistantView : UIViewController { @@ -51,6 +52,7 @@ @property(nonatomic, strong) IBOutlet UIView *remoteProvisioningLoginView; @property(strong, nonatomic) IBOutlet UIView *remoteProvisioningView; @property (strong, nonatomic) IBOutlet UIView *createAccountActivateSMSView; +@property (strong, nonatomic) IBOutlet UIView *qrCodeView; @property(nonatomic, strong) IBOutlet UIImageView *welcomeLogoImage; @property(nonatomic, strong) IBOutlet UIButton *gotoCreateAccountButton; @@ -64,6 +66,7 @@ @property (weak, nonatomic) IBOutlet UILabel *activationSMSText; @property (weak, nonatomic) IBOutlet UILabel *accountLabel; +@property (weak, nonatomic) IBOutlet UITextField *urlLabel; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *createAccountNextButtonPositionConstraint; + (NSString *)StringForXMLRPCError:(const char *)err; @@ -92,6 +95,7 @@ - (IBAction)onLoginClick:(id)sender; - (IBAction)onRemoteProvisioningLoginClick:(id)sender; - (IBAction)onRemoteProvisioningDownloadClick:(id)sender; +- (IBAction)onLaunchQRCodeView:(id)sender; - (IBAction)onCreateAccountCheckActivatedClick:(id)sender; - (IBAction)onLinkAccountClick:(id)sender; diff --git a/Classes/AssistantView.m b/Classes/AssistantView.m index 8c8e238eb..e6adb5790 100644 --- a/Classes/AssistantView.m +++ b/Classes/AssistantView.m @@ -28,6 +28,7 @@ #import "PhoneMainView.h" #import "UIAssistantTextField.h" #import "UITextField+DoneButton.h" +#import "LinphoneAppDelegate.h" typedef enum _ViewElement { ViewElement_Username = 100, @@ -134,6 +135,8 @@ static UICompositeViewDescription *compositeDescription = nil; [_contentView setContentSize:frame.size]; [_contentView contentSizeToFit]; + + _qrCodeView.frame = [[UIScreen mainScreen] bounds]; } - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { @@ -474,6 +477,13 @@ static UICompositeViewDescription *compositeDescription = nil; view = _linphoneLoginView; } } + + if (currentView == _qrCodeView) { + linphone_core_enable_video_preview(LC, FALSE); + linphone_core_enable_qrcode_video_preview(LC, FALSE); + LinphoneAppDelegate *delegate = (LinphoneAppDelegate *)UIApplication.sharedApplication.delegate; + delegate.onlyPortrait = FALSE; + } // Animation if (animation && ANIMATED) { @@ -1396,6 +1406,49 @@ void assistant_is_account_linked(LinphoneAccountCreator *creator, LinphoneAccoun }); } +- (IBAction)onLaunchQRCodeView:(id)sender { + [NSNotificationCenter.defaultCenter addObserver:self + selector:@selector(qrCodeFound:) + name:kLinphoneQRCodeFound + object:nil]; + LinphoneAppDelegate *delegate = (LinphoneAppDelegate *)UIApplication.sharedApplication.delegate; + delegate.onlyPortrait = TRUE; + NSNumber *value = [NSNumber numberWithInt:UIDeviceOrientationPortrait]; + [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; + //[UIViewController attemptRotationToDeviceOrientation]; + AVCaptureDevice *backCamera = [AVCaptureDevice defaultDeviceWithDeviceType:AVCaptureDeviceTypeBuiltInWideAngleCamera mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionBack]; + if (![[NSString stringWithUTF8String:linphone_core_get_video_device(LC)] containsString:[backCamera uniqueID]]) { + + bctbx_list_t *deviceList = linphone_core_get_video_devices_list(LC); + NSMutableArray *devices = [NSMutableArray array]; + + while (deviceList) { + char *data = deviceList->data; + [devices addObject:[NSString stringWithUTF8String:data]]; + deviceList = deviceList->next; + } + bctbx_list_free(deviceList); + + for (NSString *device in devices) { + if ([device containsString:backCamera.uniqueID]) { + linphone_core_set_video_device(LC, device.UTF8String); + } + } + } + + + linphone_core_set_native_preview_window_id(LC, (__bridge void *)(_qrCodeView)); + linphone_core_enable_video_preview(LC, TRUE); + linphone_core_enable_qrcode_video_preview(LC, TRUE); + + [NSNotificationCenter.defaultCenter addObserver:self + selector:@selector(qrCodeFound:) + name:kLinphoneQRCodeFound + object:nil]; + + [self changeView:_qrCodeView back:FALSE animation:TRUE]; +} + - (void)refreshYourUsername { UIAssistantTextField *username = [self findTextField:ViewElement_Username]; UIAssistantTextField *phone = [self findTextField:ViewElement_Phone]; @@ -1509,7 +1562,7 @@ void assistant_is_account_linked(LinphoneAccountCreator *creator, LinphoneAccoun - (IBAction)onBackClick:(id)sender { if ([historyViews count] > 0) { - if (currentView == _createAccountActivateSMSView || currentView == _createAccountActivateEmailView) { + if (currentView == _createAccountActivateSMSView || currentView == _createAccountActivateEmailView || currentView == _qrCodeView) { UIView *view = [historyViews lastObject]; [historyViews removeLastObject]; [self changeView:view back:TRUE animation:TRUE]; @@ -1532,7 +1585,7 @@ void assistant_is_account_linked(LinphoneAccountCreator *creator, LinphoneAccoun #pragma mark - select country delegate -- (void)didSelectCountry:(NSDictionary *)country{ +- (void)didSelectCountry:(NSDictionary *)country { UIRoundBorderedButton *phoneButton = [self findButton:ViewElement_PhoneButton]; [phoneButton setTitle:[country objectForKey:@"name"] forState:UIControlStateNormal]; UIAssistantTextField* countryCodeField = [self findTextField:ViewElement_PhoneCC]; @@ -1541,4 +1594,23 @@ void assistant_is_account_linked(LinphoneAccountCreator *creator, LinphoneAccoun [self shouldEnableNextButton]; } +-(void)qrCodeFound:(NSNotification *)notif { + if ([notif.userInfo count] == 0){ + return; + } + [NSNotificationCenter.defaultCenter removeObserver:self name:kLinphoneQRCodeFound object:nil]; + dispatch_async(dispatch_get_main_queue(), ^{ + self.urlLabel.text = [notif.userInfo objectForKey:@"qrcode"]; + }); + if ([historyViews count] > 0) { + if (currentView == _qrCodeView) { + UIView *view = [historyViews lastObject]; + [historyViews removeLastObject]; + [self changeView:view back:TRUE animation:TRUE]; + } else { + [self changeView:_welcomeView back:TRUE animation:TRUE]; + } + } +} + @end diff --git a/Classes/Base.lproj/AssistantViewScreens.xib b/Classes/Base.lproj/AssistantViewScreens.xib index 998c47678..6cfab070c 100644 --- a/Classes/Base.lproj/AssistantViewScreens.xib +++ b/Classes/Base.lproj/AssistantViewScreens.xib @@ -30,9 +30,11 @@ + + @@ -1347,7 +1349,7 @@ Once it is done, come back here and click on the button. - @@ -1552,6 +1554,12 @@ Once it is done, come back here and click on the button. + + + + + + diff --git a/Classes/LinphoneAppDelegate.h b/Classes/LinphoneAppDelegate.h index 93c7b1e1b..9236f4f68 100644 --- a/Classes/LinphoneAppDelegate.h +++ b/Classes/LinphoneAppDelegate.h @@ -39,6 +39,7 @@ @property PKPushRegistry* voipRegistry; @property ProviderDelegate *del; @property BOOL alreadyRegisteredForNotification; +@property BOOL onlyPortrait; @end diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index ff39eb49d..0c26035b0 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -44,6 +44,7 @@ startedInBackground = FALSE; } _alreadyRegisteredForNotification = false; + _onlyPortrait = FALSE; return self; [[UIApplication sharedApplication] setDelegate:self]; } @@ -218,17 +219,6 @@ actions:[NSArray arrayWithObjects:act_confirm, act_deny, nil] intentIdentifiers:[[NSMutableArray alloc] init] options:UNNotificationCategoryOptionCustomDismissAction]; - - // App version verification - - UNNotificationAction *act_go_to_URL = [UNNotificationAction actionWithIdentifier:@"Download" - title:NSLocalizedString(@"Download", nil) - options:UNNotificationActionOptionNone]; - UNNotificationCategory *version_verif = - [UNNotificationCategory categoryWithIdentifier:@"version_verif" - actions:[NSArray arrayWithObjects:act_go_to_URL, nil] - intentIdentifiers:[[NSMutableArray alloc] init] - options:UNNotificationCategoryOptionCustomDismissAction]; [UNUserNotificationCenter currentNotificationCenter].delegate = self; [[UNUserNotificationCenter currentNotificationCenter] requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge) @@ -238,7 +228,7 @@ LOGD(error.description); }]; - NSSet *categories = [NSSet setWithObjects:cat_call, cat_msg, video_call, cat_zrtp, version_verif, nil]; + NSSet *categories = [NSSet setWithObjects:cat_call, cat_msg, video_call, cat_zrtp, nil]; [[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:categories]; } @@ -674,10 +664,6 @@ didInvalidatePushTokenForType:(NSString *)type { }]; } else if ([response.notification.request.content.categoryIdentifier isEqual:@"lime"]) { return; - } else if ([response.notification.request.content.categoryIdentifier isEqual:@"version_verif"]) { - NSString *url = [response.notification.request.content.userInfo objectForKey:@"url"]; - [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; - return; } else { // Missed call [PhoneMainView.instance changeCurrentView:HistoryListView.compositeViewDescription]; } @@ -849,14 +835,13 @@ didInvalidatePushTokenForType:(NSString *)type { #pragma mark - Prevent ImagePickerView from rotating - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { - if ([[(PhoneMainView*)self.window.rootViewController currentView] equal:ImagePickerView.compositeViewDescription]) + if ([[(PhoneMainView*)self.window.rootViewController currentView] equal:ImagePickerView.compositeViewDescription] || _onlyPortrait) { //Prevent rotation of camera NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; return UIInterfaceOrientationMaskPortrait; - } - else return UIInterfaceOrientationMaskAllButUpsideDown; + } else return UIInterfaceOrientationMaskAllButUpsideDown; } @end diff --git a/Classes/LinphoneManager.h b/Classes/LinphoneManager.h index 498cd37ab..c1eab0464 100644 --- a/Classes/LinphoneManager.h +++ b/Classes/LinphoneManager.h @@ -56,6 +56,7 @@ extern NSString *const kLinphoneNotifyPresenceReceivedForUriOrTel; extern NSString *const kLinphoneCallEncryptionChanged; extern NSString *const kLinphoneFileTransferSendUpdate; extern NSString *const kLinphoneFileTransferRecvUpdate; +extern NSString *const kLinphoneQRCodeFound; typedef enum _NetworkType { network_none = 0, diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index 535e445f4..33deccc6d 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -76,6 +76,7 @@ NSString *const kLinphoneNotifyPresenceReceivedForUriOrTel = @"LinphoneNotifyPre NSString *const kLinphoneCallEncryptionChanged = @"LinphoneCallEncryptionChanged"; NSString *const kLinphoneFileTransferSendUpdate = @"LinphoneFileTransferSendUpdate"; NSString *const kLinphoneFileTransferRecvUpdate = @"LinphoneFileTransferRecvUpdate"; +NSString *const kLinphoneQRCodeFound = @"LinphoneQRCodeFound"; const int kLinphoneAudioVbrCodecDefaultBitrate = 36; /*you can override this from linphonerc or linphonerc-factory*/ @@ -1416,6 +1417,12 @@ void linphone_iphone_version_update_check_result_received (LinphoneCore *lc, Lin [PhoneMainView.instance presentViewController:versVerifView animated:YES completion:nil]; } +void linphone_iphone_qr_code_found(LinphoneCore *lc, const char *result) { + NSDictionary *eventDic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:result encoding:[NSString defaultCStringEncoding]] forKey:@"qrcode"]; + LOGD(@"QRCODE FOUND"); + [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneQRCodeFound object:nil userInfo:eventDic]; +} + #pragma mark - Message composition start - (void)alertLIME:(LinphoneChatRoom *)room { NSString *title = NSLocalizedString(@"LIME warning", nil); @@ -1988,6 +1995,7 @@ void popup_link_account_cb(LinphoneAccountCreator *creator, LinphoneAccountCreat linphone_core_cbs_set_chat_room_state_changed(cbs, linphone_iphone_chatroom_state_changed); linphone_core_cbs_set_version_update_check_result_received(cbs, linphone_iphone_version_update_check_result_received); linphone_core_cbs_set_user_data(cbs, (__bridge void *)(self)); + linphone_core_cbs_set_qrcode_found(cbs, linphone_iphone_qr_code_found); theLinphoneCore = linphone_factory_create_core_with_config(factory, cbs, _configDb); // Let the core handle cbs diff --git a/submodules/cmake-builder b/submodules/cmake-builder index 68f19de84..01c40162d 160000 --- a/submodules/cmake-builder +++ b/submodules/cmake-builder @@ -1 +1 @@ -Subproject commit 68f19de842824573dd075a4ec41483930b8de325 +Subproject commit 01c40162d1119a562f965b03576ddff241b5483d diff --git a/submodules/externals/zxing-cpp b/submodules/externals/zxing-cpp new file mode 160000 index 000000000..8906fb7b2 --- /dev/null +++ b/submodules/externals/zxing-cpp @@ -0,0 +1 @@ +Subproject commit 8906fb7b243fa455fd9b091e4ac611536b2dbba4