Browse Source

Coding

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 years ago
parent
commit
89dd4b75f5

+ 12 - 0
iOSClient/Images.xcassets/caldavcardav.imageset/Contents.json

@@ -0,0 +1,12 @@
+{
+  "images" : [
+    {
+      "filename" : "icons8-calendario-delle-persone.svg",
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

+ 1 - 0
iOSClient/Images.xcassets/caldavcardav.imageset/icons8-calendario-delle-persone.svg

@@ -0,0 +1 @@
+<svg fill="#000000" xmlns="http://www.w3.org/2000/svg"  viewBox="0 0 50 50" width="50px" height="50px"><path d="M48.6 32H46v-1c0-.6-.4-1-1-1s-1 .4-1 1v1h-8v-1c0-.6-.4-1-1-1s-1 .4-1 1v1h-2.6c-.8 0-1.4.6-1.4 1.4v15.3c0 .7.6 1.3 1.4 1.3h17.3c.8 0 1.3-.6 1.3-1.4V33.4C49.9 32.6 49.4 32 48.6 32zM34 34c0 .6.4 1 1 1s1-.4 1-1h8c0 .6.4 1 1 1s1-.4 1-1h2v2H32v-2H34zM35 40h2v2h-2V40zM39 40h2v2h-2V40zM43 40h2v2h-2V40zM35 44h2v2h-2V44zM39 44h2v2h-2V44zM43 44h2v2h-2V44zM30.952 7.823C30.1 6.414 28.8 5.527 27.083 5.185 26.117 3.965 24.301 3.3 21.879 3.3h-.001c-3.685.083-6.378 1.21-8.005 3.35-1.926 2.533-2.287 6.416-1.076 11.546-.413.531-.785 1.38-.688 2.54.296 2.159 1.116 3.05 1.785 3.415.308 1.749 1.156 3.676 2.007 4.597v3.561c-.611 1.376-2.601 2.172-4.892 3.089-3.864 1.546-8.673 3.47-9.007 9.549L1.943 46H28V28.747c.846-.916 1.69-2.827 2.001-4.569.712-.351 1.59-1.241 1.795-3.494.095-1.126-.215-1.954-.641-2.487C32.004 15.468 32.749 10.794 30.952 7.823zM29.059 18.164l-.316.824.793.396c.089.064.329.409.269 1.125C29.669 21.988 29.2 22.383 29.1 22.4H28.19l-.086.905c-.181 1.896-1.239 3.854-1.6 4.126L26 27.719V32.5c-.018.373-1.464 1.5-4 1.5-2.489 0-4-1.042-4-1.5 0-.152-.039-.292-.1-.421V28.3l.02-.568-.504-.288c-.381-.284-1.439-2.242-1.621-4.138l-.012-.896h-.909c-.143-.056-.59-.53-.778-1.894-.069-.838.359-1.185.358-1.185l.59-.392-.174-.687c-1.213-4.783-1.012-8.28.596-10.395 1.239-1.63 3.412-2.491 6.435-2.56 1.891 0 3.252.476 3.736 1.304l.244.419L26.36 7.09c1.332.188 2.274.766 2.881 1.769C30.689 11.254 29.926 15.735 29.059 18.164z"/></svg>

+ 30 - 4
iOSClient/Networking/NCConfigServer.swift

@@ -5,18 +5,36 @@
 //  Created by Marino Faggiana on 05/12/22.
 //  Copyright © 2022 Marino Faggiana. All rights reserved.
 //
+//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
 
 import Foundation
 import Swifter
 import NextcloudKit
 
-@objc class NCConfigServer: NSObject, UIActionSheetDelegate {
+// Source:
+// https://stackoverflow.com/questions/2338035/installing-a-configuration-profile-on-iphone-programmatically
+
+@objc class NCConfigServer: NSObject, UIActionSheetDelegate, URLSessionDelegate {
 
     // Start service
     @objc func startService(url: URL) {
 
         let defaultSessionConfiguration = URLSessionConfiguration.default
-        let defaultSession = URLSession(configuration: defaultSessionConfiguration)
+        let defaultSession = URLSession(configuration: defaultSessionConfiguration, delegate: self, delegateQueue: nil)
 
         var urlRequest = URLRequest(url: url)
         urlRequest.headers = NKCommon.shared.getStandardHeaders(nil, customUserAgent: nil)
@@ -32,6 +50,12 @@ import NextcloudKit
         dataTask.resume()
     }
 
+    func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
+        DispatchQueue.global().async {
+            NCNetworking.shared.checkTrustedChallenge(session, didReceive: challenge, completionHandler: completionHandler)
+        }
+    }
+
     private enum ConfigState: Int {
         case Stopped, Ready, InstalledConfig, BackToApp
     }
@@ -40,7 +64,7 @@ import NextcloudKit
     internal var configName: String = "Profile install"
     private var localServer: HttpServer?
     private var returnURL: String = ""
-    private var configData: Data!
+    private var configData: Data?
 
     private var serverState: ConfigState = .Stopped
     private var registeredForNotifications = false
@@ -91,7 +115,9 @@ import NextcloudKit
                 self.serverState = .InstalledConfig
                 return HttpResponse.raw(200, "OK", ["Content-Type": "application/x-apple-aspen-config"], { writer in
                     do {
-                        try writer.write(self.configData)
+                        if let configData = self.configData {
+                            try writer.write(configData)
+                        }
                     } catch {
                         print("Failed to write response data")
                     }

+ 1 - 1
iOSClient/Networking/NCNetworking.swift

@@ -155,7 +155,7 @@ import Photos
 
     // MARK: - Pinning check
 
-    private func checkTrustedChallenge(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
+    public func checkTrustedChallenge(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
 
         let protectionSpace: URLProtectionSpace = challenge.protectionSpace
         let directoryCertificate = CCUtility.getDirectoryCerificates()!

+ 7 - 7
iOSClient/Settings/NCSettings.m

@@ -49,8 +49,7 @@
     XLFormDescriptor *form = [XLFormDescriptor formDescriptor];
     XLFormSectionDescriptor *section;
     XLFormRowDescriptor *row;
-    //NSInteger serverVersionMajor = [[NCManageDatabase shared] getCapabilitiesServerIntWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesVersionMajor];
-    
+
     form.rowNavigationOptions = XLFormRowNavigationOptionNone;
     
     // Section AUTO UPLOAD OF CAMERA IMAGES ----------------------------
@@ -100,17 +99,17 @@
     [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
     [section addFormRow:row];
 
-    // Section : CARDAV --------------------------------------------------------------
+    // Section : CALDAV CARDAV --------------------------------------------------------------
 
-    section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_cardav_", nil)];
+    section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_calendar_contacts_", nil)];
     [form addFormSection:section];
 
-    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"cardav" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_cardav_", nil)];
+    row = [XLFormRowDescriptor formRowDescriptorWithTag:@"caldavcardav" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_mobile_config_", nil)];
     row.cellConfigAtConfigure[@"backgroundColor"] = UIColor.secondarySystemGroupedBackgroundColor;
     [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
     [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
     [row.cellConfig setObject:UIColor.labelColor forKey:@"textLabel.textColor"];
-    [row.cellConfig setObject:[[UIImage imageNamed:@"shield.checkerboard"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
+    [row.cellConfig setObject:[[UIImage imageNamed:@"caldavcardav"] imageWithColor:NCBrandColor.shared.gray size:25] forKey:@"imageView.image"];
     row.action.formSelector = @selector(CalDAVCardDAV:);
     [section addFormRow:row];
 
@@ -350,7 +349,6 @@
     [self deselectFormRow:sender];
 
     NSString *url = [appDelegate.urlBase stringByAppendingString:@"/remote.php/dav/provisioning/apple-provisioning.mobileconfig"];
-    //[[NCConfigServer shared] startServiceWithUrl:[NSURL URLWithString: url]];
     NCConfigServer *configServer = [NCConfigServer new];
     [configServer startServiceWithUrl:[NSURL URLWithString: url]];
 }
@@ -452,6 +450,8 @@
 
     if (section == 1) {
         sectionName = NSLocalizedString(@"_lock_protection_no_screen_footer_", nil);
+    } else if (section == 2) {
+        sectionName = NSLocalizedString(@"_calendar_contacts_footer_", nil);
     } else if (section == numSections) {
         NSString *versionServer = [[NCManageDatabase shared] getCapabilitiesServerStringWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesVersionString];
         NSString *themingName = [[NCManageDatabase shared] getCapabilitiesServerStringWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesThemingName];

+ 4 - 1
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -897,7 +897,7 @@
 "_keep_running_"            = "Keep the app running for a better user experience";
 "_recent_activity_"         = "Recent activity";
 "_title_lockscreenwidget_"  = "Status";
-"_description_lockscreenwidget_" = "Keep an eye on available space and recent activity";
+"_description_lockscreenwidget_"    = "Keep an eye on available space and recent activity";
 "_no_items_"                = "No items";
 "_check_back_later_"        = "Check back later";
 "_exporting_video_"         = "Exporting video … Tap to cancel.";
@@ -909,6 +909,9 @@
 "_change_upload_filename_"  = "Do you want to save the file with a different name ?";
 "_save_file_as_"            = "Save file as %@";
 "_password_ascii_"          = "The password cannot contain special characters";
+"_calendar_contacts_"       = "Calendar and Contacts";
+"_mobile_config_"           = "Download the Mobile Config";
+"_calendar_contacts_footer_"    = "xxxx";
 
 // Video
 "_select_trace_"            = "Select the trace";