教程

作者: 改变1 | 来源:发表于2020-12-25 15:15 被阅读0次

    注1:等需要提交包到苹果商店时,集成此静态库,设置xcode运行环境为Release。如

    image.png
    image.png
    注2:如果Xcode为版本为12.3或者以上,可能会出现此问题:
    image.png
    解决方案为进入Build Settings搜索Validate WorkSpace:
    image.png
    详情见http://okgoes.cn/blog/detail?blog_id=25339

    一.下载文件解压后得到


    image.png

    二.直接拖入工程


    image.png
    三.设置最低支持版本并去掉ipad支持
    image.png
    image.png

    四.更改bitcode为NO


    更改bitcode
    五.配置库链接,此处如果不进行配置
    1.先创建Copy Files文件
    创建Copy Files
    2.点击Copy Files选项,更改设置Destination的Resource为Frameworks
    更改设置Destination
    3.分别拖入TiSDK.framework和ImSDK.framework两个文件
    拖入文件
    注:如果在第六步pod完成之后,启动app的时候控制台发现此问题,请检查或者重新配置一次库链接
    配置错误或者没有配置时

    六.用pod安装工程依赖公共三方库
    为了防止和静态库依赖工程所添加的三方依赖库重复或者冲突,所以需要用pod加载静静态库依赖文件。打开pod文件后复制下面三方库后执行pod install

    pod 'AFNetworking'
    pod 'MMLayout', '0.2.0'
    pod 'Toast'
    pod 'ReactiveObjC'
    pod 'FMDB', '~> 2.7.5'
    pod 'Bugly'
    pod 'JVerification'
    pod 'SVGAPlayer', '2.5.2'
    pod 'TZImagePickerController'
    pod 'RTRootNavigationController', '~> 0.7.1'
    pod 'SVProgressHUD'
    pod 'MJExtension', '~> 3.0.15.1'
    pod 'YYKit'
    pod 'Masonry', '~> 1.1.0'
    pod 'MJRefresh', '~> 3.1.15.7'
    pod 'ZFPlayer', '~> 3.2.17'
    pod 'Reachability'
    pod 'SDWebImage'
    pod 'libOpenInstallSDK'
    

    安装成功后,退出项目,点击.xcworkspace工作空间重新打开项目。到此,静态库运行全部依赖已经配置完成,command+r运行下项目是可以启动成功的。


    image.png

    八.设置Generate Debug Symbols
    需要Generate Debug Symbols为Yes


    image.png
    九.配置跳转,复制如下代码
    1.png

    导入头文件

    #import "ViewController.h"
    #import <TBEVideo/TBEWebBridgeManager.h>
    

    添加代码

     [TBEWebBridgeManager getAppConfiguration:^(NSDictionary * _Nonnull resultData) {
            NSNumber *openNumber = resultData[@"tbrInfo"];
            if (openNumber.boolValue) {
                //注意项目中必须有根控制器(UINavigationController,vc必须有UINavigationController),webview不要直接添加在window上。如果没有根控制器,静态库没有办法实现跳转等逻辑。请注意简书上初始化webview的添加位置,静态库中获取到webView后会取所在的VC并隐藏导航栏,务必注意。
                //将已经初始化好的webView给入,打开webapp
                self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
                self.window.backgroundColor = [UIColor whiteColor];
                [self.window makeKeyAndVisible];
                ViewController *update = [[ViewController alloc] init];
                UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:update];
                self.window.rootViewController = nav;
                
                [[TBEWebBridgeManager sharedManager] setWebView:update.webView];
            }else {
                //自己工程的逻辑
            }
        }];
    

    ViewController部分:


    2.png

    ViewController.h文件添加代码

    #import <WebKit/WebKit.h>
    
    @property (nonatomic, strong) WKWebView *webView;
    
    3.png

    ViewController.m文件添加代码

    - (instancetype)init {
        self = [super init];
        if (self) {
            _webView = [[WKWebView alloc] init];
            _webView.backgroundColor = UIColor.whiteColor;
            [self.view addSubview:_webView];
            
            [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.right.bottom.equalTo(self.view);
            }];
        }
        return self;
    }
    

    十.配置info文件



    用到的权限如下:
    Privacy - Camera Usage Description描述为:应用将在您设置头像的时候访问您的相机
    Privacy - Microphone Usage Description描述为:应用将在您发送语音的时候访问您的麦克风权限
    Privacy - Photo Library Additions Usage Description描述为:应用将在您设置头像的时候访问您的相册
    Privacy - Photo Library Usage Description描述为:应用将在您发送图片时访问您的相册
    Privacy - Location When In Use Usage Description描述为:应用将在您发布动态圈的时候访问您的位置
    Privacy - Speech Recognition Usage Description描述为:应用在输入文字时需要使用您的语音功能
    Privacy - Contacts Usage Description描述为:应用将在您拨打电话时访问您的通讯录权限
    配置http请求权限(必要设置,否则可能出现web打开端无法使用,网络请求失败等情况)
    增加App Transport Security Settings后,再往此配置下增加Allow Arbitrary Loads配置,并设置此配置为YES,如下图


    image.png

    十一.锁定竖屏


    image.png

    十二.增加推送
    推送证书的配置在此不做阐述


    image.png

    十三.增加符号表收集


    image.png

    添加下列代码到


    image.png
    
    BUGLY_APP_ID="84e80ad84e"
    # #
    BUGLY_APP_KEY="da314a92-c246-4136-8ac4-0d1e6aaa2582"
    # #
    BUNDLE_IDENTIFIER=$(PRODUCT_BUNDLE_IDENTIFIER)
    # #
    UPLOAD_DSYM_ONLY=1
    #
    # # 脚本默认配置的版本格式为CFBundleShortVersionString(CFBundleVersion),  如果你修改默认的版本格式, 请设置此变量, 如果不想修改, 请忽略此设置
    # CUSTOMIZED_APP_VERSION=""
    #
    # # Debug模式编译是否上传,1=上传 0=不上传,默认不上传
    # UPLOAD_DEBUG_SYMBOLS=0
    #
    # # 模拟器编译是否上传,1=上传 0=不上传,默认不上传
    # UPLOAD_SIMULATOR_SYMBOLS=0
    #
    # #只有Archive操作时上传, 1=支持Archive上传 0=所有Release模式编译都上传
    # UPLOAD_ARCHIVE_ONLY=0
    #
    # #
    # source dSYMUpload.sh
    #
    # --- END OF SCRIPT ---
    #
    #
    #
    #
    #######################################################
    # 2. 脚本根据输入参数处理
    #######################################################
    #
    # #命令行下输入应用基本信息, .dSYM文件的父目录路径, 输出文件目录即可
    #
    # sh dSYMUpload.sh <bugly_app_id> <bugly_app_key> <app_bundle_identifier> <app_version> <dSYM_src_dir> <bSYMBOL_dest_dir>
    
    # --- CONTENT OF SCRIPT ---
    #
    
    # Bugly服务域名
    BUGLY_DSYM_UPLOAD_DOMAIN="api.bugly.qq.com"
    
    # 注意jar工具的路径跟dSYMUpload.sh脚本路径一致, 请务必保证jar路径的正确性
    BUGLY_SYMBOL_JAR_PATH="dsymtool/buglySymboliOS.jar"
    # 查找添加到系统目录的jar工具
    if [ ! -f "${BUGLY_SYMBOL_JAR_PATH}" ]; then
        BUGLY_SYMBOL_JAR_PATH="$HOME/bin/buglySymboliOS.jar"
    fi
    
    # 打印错误信息
    function exitWithMessage(){
        echo "--------------------------------"
        echo "${1}"
        echo "--------------------------------"
        exit ${2}
    }
    
    # 上传bSYMBOL文件
    function dSYMUpload() {
        P_APP_ID="$1"
        P_APP_KEY="$2"
        P_APP_BUNDLE_ID="$3"
        P_APP_VERSION="$4"
        P_BSYMBOL_ZIP_FILE="$5"
    
        #
        P_BSYMBOL_ZIP_FILE_NAME=${P_BSYMBOL_ZIP_FILE##*/}
        P_BSYMBOL_ZIP_FILE_NAME=${P_BSYMBOL_ZIP_FILE_NAME//&/_}
        P_BSYMBOL_ZIP_FILE_NAME="${P_BSYMBOL_ZIP_FILE_NAME// /_}"
    
        DSYM_UPLOAD_URL="https://${BUGLY_DSYM_UPLOAD_DOMAIN}/openapi/file/upload/symbol?app_id=${P_APP_ID}&app_key=${P_APP_KEY}"
        echo "dSYM upload url: ${DSYM_UPLOAD_URL}"
    
        echo "-----------------------------"
        STATUS=$(/usr/bin/curl -k "${DSYM_UPLOAD_URL}" --form "api_version=1" --form "app_id=${P_APP_ID}" --form "app_key=${P_APP_KEY}" --form "symbolType=2"  --form "bundleId=${BUNDLE_IDENTIFIER}" --form "productVersion=${BUGLY_APP_VERSION}" --form "fileName=${P_BSYMBOL_ZIP_FILE_NAME}" --form "file=@${P_BSYMBOL_ZIP_FILE}" --verbose)
        echo "-----------------------------"
    
        UPLOAD_RESULT="FAILTURE"
        echo "Bugly server response: ${STATUS}"
        if [ ! "${STATUS}" ]; then
            echo "Error: Failed to upload the zip archive file."
        elif [[ "${STATUS}" == *"{\"reponseCode\":\"0\"}"* ]]; then
            echo "Success to upload the dSYM for the app [${BUNDLE_IDENTIFIER} ${BUGLY_APP_VERSION}]"
            UPLOAD_RESULT="SUCCESS"
        else
            echo "Error: Failed to upload the zip archive file to Bugly."
        fi
    
        #Remove temp dSYM archive
        #echo "Remove temporary zip archive: ${DSYM_ZIP_FPATH}"
        #/bin/rm -f "${DSYM_ZIP_FPATH}"
    
        if [ "$?" -ne 0 ]; then
            exitWithMessage "Error: Failed to remove temporary zip archive." 0
        fi
    
        echo "--------------------------------"
        echo "${UPLOAD_RESULT} - dSYM upload complete."
    
        if [[ "${UPLOAD_RESULT}" == "FAILTURE" ]]; then
            echo "--------------------------------"
            echo "Failed to upload the dSYM"
            echo "Please check the script and try it again."
        fi
    }
    
    # .dSYM解析为bSYMBOL文件
    function dSYMParse() {
        DSYM_FILE="$1"
        DSYM_SYMBOL_FILE="$2"
    
        echo "--------------------------------"
        echo "Extract symbol info from .dSYM file. to ${DSYM_SYMBOL_FILE}"
        (/usr/bin/java -Xms512m -Xmx1024m -Dfile.encoding=UTF8 -jar "${BUGLY_SYMBOL_JAR_PATH}" -i "${DSYM_FILE}" -o "${DSYM_SYMBOL_FILE}" ) || exitWithMessage "Error: Failed to extract symbols." 1
        echo "--------------------------------"
    
    }
    
    # 执行
    function run() {
    
        CONFIG_BUGLY_APP_ID="$1"
        CONFIG_BUGLY_APP_KEY="$2"
    
        CONFIG_BUGLY_APP_BUNDLE_IDENTIFIER="$3"
        CONFIG_BUGLY_APP_VERSION="$4"
        CONFIG_DSYM_SOURCE_DIR="$5"
        CONFIG_DSYM_DEST_DIR="$6"
        CONFIG_UPLOAD_DSYM_ONLY="$7"
    
        # 检查必须参数是否设置
        if [ ! "${CONFIG_BUGLY_APP_ID}" ]; then
            exitWithMessage "Error: Bugly App ID not defined. Please set 'BUGLY_APP_ID' " 0
        fi
    
        if [[ "${CONFIG_BUGLY_APP_ID}" == *"App ID"* ]]; then
            exitWithMessage "Error: Bugly App ID not defined." 0
        fi
    
        if [ ! "${CONFIG_BUGLY_APP_KEY}" ]; then
            exitWithMessage "Error: Bugly App Key not defined." 0
        fi
    
        if [ ! "${CONFIG_BUGLY_APP_BUNDLE_IDENTIFIER}" ]; then
            exitWithMessage "Error: Bundle Identifier not defined." 0
        fi
    
        if [ ! "${CONFIG_BUGLY_APP_VERSION}" ]; then
            exitWithMessage "Error: App Version not defined." 0
        fi
    
        if [ ! -e "${CONFIG_DSYM_SOURCE_DIR}" ]; then
            exitWithMessage "Error: Invalid dir ${CONFIG_DSYM_SOURCE_DIR}" 0
        fi
    
        if [ ! "${CONFIG_DSYM_DEST_DIR}" ]; then
            exitWithMessage "Error: Invalid dir ${CONFIG_DSYM_DEST_DIR}" 0
        fi
    
        if [ ! -e "${CONFIG_DSYM_DEST_DIR}" ]; then
            mkdir ${CONFIG_DSYM_DEST_DIR}
        fi
    
        DSYM_FOLDER="${CONFIG_DSYM_SOURCE_DIR}"
        IFS=$'\n'
    
        echo "Scaning dSYM FOLDER: ${DSYM_FOLDER} ..."
        RET="F"
        
        #
        for dsymFile in $(find "$DSYM_FOLDER" -name '*.dSYM'); do
            RET="T"
            echo "Found dSYM file: $dsymFile"
    
            DSYM_FILE_NAME=${dsymFile##*/}
            DSYM_SYMBOL_ZIP_FILE_NAME="${DSYM_FILE_NAME}.zip"
            DSYM_SYMBOL_ZIP_FILE_NAME="${DSYM_SYMBOL_ZIP_FILE_NAME// /_}"
            DSYM_SYMBOL_ZIP_FILE=${CONFIG_DSYM_DEST_DIR}/${DSYM_SYMBOL_ZIP_FILE_NAME}
    
            if [ $CONFIG_UPLOAD_DSYM_ONLY -eq 1 ]; then
                if [ -e $DSYM_SYMBOL_ZIP_FILE ]; then
                    rm -f $DSYM_SYMBOL_ZIP_FILE
                fi
                # 如果只上传dSYM,直接压缩dSYM目录
                zip -r -j $DSYM_SYMBOL_ZIP_FILE $dsymFile -x *.plist
            else
                # 使用符号表工具来生成Symbol文件
                dSYMParse $dsymFile $DSYM_SYMBOL_ZIP_FILE
            fi
            
            # 上传
            dSYMUpload $CONFIG_BUGLY_APP_ID $CONFIG_BUGLY_APP_KEY $CONFIG_BUGLY_APP_BUNDLE_IDENTIFIER $CONFIG_BUGLY_APP_VERSION $DSYM_SYMBOL_ZIP_FILE
        done
    
        if [ $RET = "F" ]; then
            exitWithMessage "No .dSYM found in ${DSYM_FOLDER}" 0
        fi
    }
    
    # 在Xcode工程中执行
    function runInXcode(){
        echo "Uploading dSYM to Bugly in Xcode ..."
    
        echo "Info.Plist : ${INFOPLIST_FILE}"
    
        BUNDLE_VERSION=$(/usr/libexec/PlistBuddy -c 'Print CFBundleVersion' "${INFOPLIST_FILE}")
        BUNDLE_SHORT_VERSION=$(/usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' "${INFOPLIST_FILE}")
    
        # 组装Bugly默认识别的版本信息(格式为CFBundleShortVersionString(CFBundleVersion), 例如: 1.0(1))
        if [ ! "${CUSTOMIZED_APP_VERSION}" ]; then
            BUGLY_APP_VERSION="${BUNDLE_SHORT_VERSION}(${BUNDLE_VERSION})"
        else
            BUGLY_APP_VERSION="${CUSTOMIZED_APP_VERSION}"
        fi
    
        echo "--------------------------------"
        echo "Prepare application information."
        echo "--------------------------------"
    
        echo "Product Name: ${PRODUCT_NAME}"
        echo "Bundle Identifier: ${BUNDLE_IDENTIFIER}"
        echo "Version: ${BUNDLE_SHORT_VERSION}"
        echo "Build: ${BUNDLE_VERSION}"
    
        echo "Bugly App ID: ${BUGLY_APP_ID}"
        echo "Bugly App key: ${BUGLY_APP_KEY}"
        echo "Bugly App Version: ${BUGLY_APP_VERSION}"
    
        echo "--------------------------------"
        echo "Check the arguments ..."
    
        ##检查模拟器编译是否允许上传符号
        if [ "$EFFECTIVE_PLATFORM_NAME" == "-iphonesimulator" ]; then
        if [ $UPLOAD_SIMULATOR_SYMBOLS -eq 0 ]; then
            exitWithMessage "Warning: Build for simulator and skipping to upload. \nYou can modify 'UPLOAD_SIMULATOR_SYMBOLS' to 1 in the script." 0
        fi
        fi
    
        ##检查是否是Release模式编译
        if [ "${CONFIGURATION=}" == "Debug" ]; then
        if [ $UPLOAD_DEBUG_SYMBOLS -eq 0 ]; then
            exitWithMessage "Warning: Build for debug mode and skipping to upload. \nYou can modify 'UPLOAD_DEBUG_SYMBOLS' to 1 in the script." 0
        fi
        fi
    
        ##检查是否Archive操作
        if [ $UPLOAD_ARCHIVE_ONLY -eq 1 ]; then
        if [[ "$TARGET_BUILD_DIR" == *"/Archive"* ]]; then
            echo "Archive the package"
        else
            exitWithMessage "Warning: Build for NOT Archive mode and skipping to upload. \nYou can modify 'UPLOAD_ARCHIVE_ONLY' to 0 in the script." 0
        fi
        fi
    
        #
        run ${BUGLY_APP_ID} ${BUGLY_APP_KEY} ${BUNDLE_IDENTIFIER} ${BUGLY_APP_VERSION} ${DWARF_DSYM_FOLDER_PATH} ${BUILD_DIR}/BuglySymbolTemp ${UPLOAD_DSYM_ONLY}
    }
    
    # 根据Xcode的环境变量判断是否处于Xcode环境
    INFO_PLIST_FILE="${INFOPLIST_FILE}"
    
    BuildInXcode="F"
    if [ -f "${INFO_PLIST_FILE}" ]; then
        BuildInXcode="T"
    fi
    
    if [ $BuildInXcode = "T" ]; then
        runInXcode
    else
        echo "\nUsage: dSYMUpload.sh <bugly_app_id> <bugly_app_key> <app_bundle_identifier> <app_version> <dSYM_src_dir> <bSYMBOL_dest_dir> [upload_dsym_only]\n"
        # 你可以在此处直接设置BuglyAppID和BuglyAppKey,排除不常变参数的输入
        BUGLY_APP_ID="$1"
        BUGLY_APP_KEY="$2"
        BUNDLE_IDENTIFIER="$3"
        BUGLY_APP_VERSION="$4"
        DWARF_DSYM_FOLDER_PATH="$5"
        SYMBOL_OUTPUT_PATH="$6"
        UPLOAD_DSYM_ONLY=$7
        run ${BUGLY_APP_ID} ${BUGLY_APP_KEY} ${BUNDLE_IDENTIFIER} ${BUGLY_APP_VERSION} ${DWARF_DSYM_FOLDER_PATH} ${SYMBOL_OUTPUT_PATH} ${UPLOAD_DSYM_ONLY}
    fi
    

    相关文章

      网友评论

          本文标题:教程

          本文链接:https://www.haomeiwen.com/subject/kxnsnktx.html