iOS一些小技巧 | 五

一,OSS私有文件增加验签,本地SDK在URL后增加签名,无需网络请求权限:

//
//
func ossImageUrlAddVerificationSignature(filePath: String) -> String? {
    
    guard let ossParamsModel = self.ossSignModel else {
        return nil;
    }
    
    let endpoint: String = ossParamsModel.endpoint;
    let accessKeyId: String = ossParamsModel.accessKeyId;
    let accessKeySecret: String = ossParamsModel.accessKeySecret;
    //objectKey为文件在OSS中的路径+文件名
    let objectKey: String = filePath;
    
    let credential = OSSStsTokenCredentialProvider(accessKeyId: accessKeyId, secretKeyId: accessKeySecret, securityToken: "");
    let client = OSSClient(endpoint: endpoint, credentialProvider: credential)
    let task = client.presignConstrainURL(withBucketName: AlibabaOSSImageServerBucketName, withObjectKey: objectKey, httpMethod: "GET", withExpirationInterval: 60 * 4, withParameters: [:]);
    var signatureUrl: String?;
    task.continue({ task in
        if nil == task.error {
            signatureUrl = task.result as? String;
        }
        return nil;
    });
    return signatureUrl;
}
//
//

二,git开启LFS上传大文件;

//1,安装
brew install git-lfs
//2,查看是否成功和版本
git lfs -v
//3,将本地大文件交给lfs管理,可多次执行
git lfs track "文件名"
//4,查看当前lfs管理的文件列表
git lfs track
//5,提交暂存区、本地及将大文件推送到远程管理,包括.gitattributes文件
git add .
git commit -m "msg"
git push
//6,再拉取一下大文件
git lfs pull
//7,将文件交给lfs管理,可执行多次
git lfs migrate import --include-ref=master --include="FlowerClassifier.mlmodel"
git lfs migrate import --include-ref=master --include="MLKitTextRecognitionCommon"
git lfs migrate import --include-ref=master --include="MLKitVisionKit"
git lfs migrate import --include-ref=master --include="MLKitXenoCommon"
//8,提交
git push --all --force
或
git push

三,bash和zsh之间的切换;

//判断当前是bash还是zsh
echo $SHELL
//切换到bash
chsh -s /bin/bash
//切换到zsh
chsh -s /bin/zsh

四,iOS18,TranslateAPI在swift中混编swiftUI,让其翻译指定的句子:

//
//

import SwiftUICore
import UIKit
import SwiftUI

struct SkyAppleTranslateView: View {
    @State private var showTranslation = true;

    // Define the text you want to translate.
    var originalText: String;

    var body: some View {
        VStack {
        }
        // Offer a system UI translation.
        .translationPresentation(isPresented: $showTranslation,
                                 text: originalText)
        .navigationTitle("translate")
    }
    
    
    static func showInController(controller: UIViewController, translateString: String) -> Void {
        if translateString.count <= 0 {
            return;
        }
        let translateView = SkyAppleTranslateView(originalText: translateString);
        let hostingController = UIHostingController(rootView: translateView);
        hostingController.view.isHidden = true;
        controller.addChild(hostingController)
        controller.view.addSubview(hostingController.view)
        hostingController.view.frame = controller.view.bounds
        hostingController.didMove(toParent: controller)
    }
}
//
//

使用:
@objc func translateEvent(_ bt: UIButton) -> Void {
   SkyAppleTranslateView.showInController(controller: self, translateString: "你好,世界!");
}

Leave a Reply

Required fields are marked *