From dd5bc2f5cf12b3814ea45d4ca99691cee9a11089 Mon Sep 17 00:00:00 2001 From: Christophe Deschamps Date: Thu, 3 Oct 2024 13:52:32 +0200 Subject: [PATCH] Ask user permission for smart address book --- Classes/LinphoneManager.m | 10 +++++++ Classes/Swift/SwiftUtil.swift | 35 +++++++++++++++++++++++ Classes/Swift/Voip/Theme/VoipTexts.swift | 7 +++++ Classes/Utils/FastAddressBook.m | 6 +++- Resources/fr.lproj/Localizable.strings | Bin 77950 -> 79510 bytes 5 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Classes/LinphoneManager.m b/Classes/LinphoneManager.m index adef69ff2..06b5a1bbf 100644 --- a/Classes/LinphoneManager.m +++ b/Classes/LinphoneManager.m @@ -1452,8 +1452,18 @@ void popup_link_account_cb(LinphoneAccountCreator *creator, LinphoneAccountCreat linphone_core_cbs_set_conference_state_changed(cbs, linphone_iphone_conference_state_changed); + bool reEnableRls = false; + if (![LinphoneManager.instance lpConfigBoolForKey:@"use_rls_presence_requested"] && [LinphoneManager.instance lpConfigBoolForKey:@"use_rls_presence"]) { + [LinphoneManager.instance lpConfigSetBool:false forKey:@"use_rls_presence"]; + reEnableRls = true; + } theLinphoneCore = linphone_factory_create_shared_core_with_config(factory, _configDb, NULL, [kLinphoneMsgNotificationAppGroupId UTF8String], true); + + if (bctbx_list_size(linphone_core_get_account_list(theLinphoneCore)) > 0 && reEnableRls) { // Do not request rls allowance for users who had it before. + [LinphoneManager.instance lpConfigSetBool:true forKey:@"use_rls_presence"]; + } + linphone_core_enable_auto_iterate(theLinphoneCore, true); linphone_core_set_chat_messages_aggregation_enabled(theLinphoneCore, false); linphone_core_add_callbacks(theLinphoneCore, cbs); diff --git a/Classes/Swift/SwiftUtil.swift b/Classes/Swift/SwiftUtil.swift index fe28f288c..a9adb2adc 100644 --- a/Classes/Swift/SwiftUtil.swift +++ b/Classes/Swift/SwiftUtil.swift @@ -131,7 +131,42 @@ import linphonesw } else { Log.e("Invalid URL \(urlString)") } + } + + @objc static func requestRLSPresenceAllowance() { + let rls = UIAlertController( + title: VoipTexts.accept_rls_title, + message: VoipTexts.accept_rls, + preferredStyle: .actionSheet) + let accept = UIAlertAction( + title: VoipTexts.dialog_accept, + style: .default, + handler: { action in + Core.get().config?.setInt(section: "app", key: "use_rls_presence", value: 1) + Core.get().config?.setInt(section: "app", key: "use_rls_presence_requested", value: 1) + Core.get().friendListSubscriptionEnabled = true + }) + let refuse = UIAlertAction( + title: VoipTexts.dialog_later, + style: .default, + handler: { action in + Core.get().config?.setInt(section: "app", key: "use_rls_presence", value: 0) + Core.get().config?.setInt(section: "app", key: "use_rls_presence_requested", value: 1) + Core.get().friendListSubscriptionEnabled = false + }) + let pp = UIAlertAction( + title: VoipTexts.dialog_privacy_policy, + style: .default, + handler: { action in + openUrl(urlString: "https://www.linphone.org/privacy-policy") + }) + + rls.addAction(accept) + rls.addAction(pp) + rls.addAction(refuse) + rls.popoverPresentationController?.sourceView = PhoneMainView.instance().mainViewController.statusBarView + PhoneMainView.instance()?.present(rls, animated: true) } } diff --git a/Classes/Swift/Voip/Theme/VoipTexts.swift b/Classes/Swift/Voip/Theme/VoipTexts.swift index 99446b6f9..1058db916 100644 --- a/Classes/Swift/Voip/Theme/VoipTexts.swift +++ b/Classes/Swift/Voip/Theme/VoipTexts.swift @@ -250,4 +250,11 @@ import UIKit static let conference_info_confirm_removal_delete = NSLocalizedString("DELETE",comment:"") static let conference_unable_to_share_via_calendar = NSLocalizedString("Unable to add event to calendar. Check permissions",comment:"") static let screenshot_restrictions = NSLocalizedString("Can't take a screenshot due to app restrictions", comment: "") + + + @objc static let dialog_later = NSLocalizedString("Maybe later",comment:"") + @objc static let dialog_privacy_policy = NSLocalizedString("Privacy policy",comment:"") + @objc static let accept_rls_title = NSLocalizedString("Enable smart address book", comment:"") + @objc static let accept_rls = NSLocalizedString("To provide the best experience, your contacts phone numbers will be uploaded to our secure servers. We value your privacy, and this data will only be used as outlined in our privacy policy. You can disable this option any time in application settings",comment:"") + } diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index 1fc2639d5..c007f19d7 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -216,7 +216,11 @@ BOOL success = FALSE; if(granted){ LOGD(@"CNContactStore authorization granted"); - + dispatch_async(dispatch_get_main_queue(), ^{ + if (bctbx_list_size(linphone_core_get_account_list(LC)) == 0 && ![LinphoneManager.instance lpConfigBoolForKey:@"use_rls_presence_requested"]) { + [SwiftUtil requestRLSPresenceAllowance]; + } + }); NSError *contactError; CNContactStore* store = [[CNContactStore alloc] init]; [store containersMatchingPredicate:[CNContainer predicateForContainersWithIdentifiers:@[ store.defaultContainerIdentifier]] error:&contactError]; diff --git a/Resources/fr.lproj/Localizable.strings b/Resources/fr.lproj/Localizable.strings index 25ff586b0fb7a1d5b31693a44b50618756e54949..5e0146c8fd0f4b9a1a7770f9e81b2fd526e725f7 100644 GIT binary patch delta 1037 zcmY*XJ!=$E6urvEB8mwKk*vw$>=ud;<0K#!vPBT9fcOPsIhkEI!QFZ5d~A|JM@tI@ zy=W)cYMt8F#@`Uq?t-1Qc+P#Bjq;e8_ujqt+;h*FKSz~MzbdZ|PQ46oPs??zhtiWs zQpqKd4QXMe(v}P>kS%do&#;T6i{)e&yF_ASOiM%VX=hZMYTEAYs99~u9YiD4b&(MO zV~nl!a7n}2b9#PbPCpzr^xf>4T8Br73 zlE8=zCYYfUSq8QvelX zTV|400#QkhlF%Gqb%ZEK&JkfIXz9n{4Sle=JkzovITn!zx^{E^%KwJ5ntwNY(