美文网首页
iOS 用脚本添加sdk库

iOS 用脚本添加sdk库

作者: KeyboardLife | 来源:发表于2019-10-22 10:21 被阅读0次
    #!/usr/bin/env ruby
    require 'xcodeproj'
    
    #打开项目工程
    project_path = './leitinglib.xcodeproj'
    project = Xcodeproj::Project.open(project_path)
    target = project.targets.first
    
    #找到要插入的group(参数中的true表示如果找不到group,就创建一个group)
    group = project.main_group.find_subpath('leitinglib/framework/qiyuSDK',true)
    group.set_source_tree('<group>')
    
    group_QYAccessLayer = project.main_group.find_subpath('leitinglib/feature/QYSDK',true)
    group_QYAccessLayer.set_source_tree('<group>')
    
    #AIHelp相关
    group_AIHelp = project.main_group.find_subpath('leitinglib/framework/ElvaChatServiceSDK',true)
    group_AIHelp_H_M = project.main_group.find_subpath('leitinglib/feature/AIHelp',true)
    
    
    #智齿相关
    group_zhichi = project.main_group.find_subpath('leitinglib/framework/zhichiSDK',true)
    group_zhichi_H_M = project.main_group.find_subpath('leitinglib/feature/ZCSDK',true)
    
    
    
    #递归添加索引
    def addFilesToGroup(aTarget, aGroup, filePath, fileName)
        if File.directory? filePath
            # 当前文件为目录
            Dir.foreach(filePath) do |file|
                if file.to_s.end_with?(".bundle")
                    #bundle文件属于目录,直接添加引用
                    puts "添加#{file}"
                    file_ref = aGroup.new_reference(File.join(filePath, file))
                    aTarget.add_resources([file_ref])
                elsif file !="." && file !=".."then
                    subPath = File.join(filePath, file)
                    if File.directory? subPath
                        #子文件也属于目录,添加新的group
                        newGroup = aGroup.find_subpath(file,true)
                        
                        #递归添加索引
                        addFilesToGroup(aTarget, newGroup, subPath, fileName+"/"+file)
                    else
                        #递归添加索引
                        addFilesToGroup(aTarget, aGroup, subPath, fileName+"/"+file )
                    end
                end
            end
        else
        #puts("fileName=",fileName)
            # 过滤目录和.DS_Store文件
            if fileName.to_s.end_with?(".h") || fileName.to_s.end_with?(".m")
                #h或m文件
                puts "添加#{fileName}"
                file_ref = aGroup.new_reference(fileName)
                aTarget.add_file_references([file_ref])
            elsif fileName.to_s.end_with?(".a")
                #.a库
                puts "添加#{fileName}"
                file_ref = aGroup.new_reference(fileName)
                aTarget.frameworks_build_phases.add_file_reference(file_ref)
            end
        end
    end
    
    
    #删除索引
    def removeBuildPhaseFilesRecursively(aTarget, aGroup)
        aGroup.files.each do |file|
            
            if file.real_path.to_s.end_with?(".m", ".mm", ".cpp") then
                aTarget.source_build_phase.remove_file_reference(file)
                elsif file.real_path.to_s.end_with?(".bundle") then
                aTarget.resources_build_phase.remove_file_reference(file)
    #            elsif file.real_path.to_s.end_with?(".a") then
    #            aTarget.frameworks_build_phases.remove_file_reference(file)
            end
        end
        
        aGroup.groups.each do |group|
            removeBuildPhaseFilesRecursively(aTarget, group)
        end
    end
    
    #修改leitinglib/util/ConstantsUtil.h文件中宏定义 引入不同的客服工具,比如七鱼、智齿、AIHelp
    text = File.read("leitinglib/util/ConstantsUtil.h")
    replace = text.gsub("USE_ZHICHI_YES","USE_QIYU_YES")
    replace = replace.gsub("USE_AIHELP_YES","USE_QIYU_YES")
    File.open("leitinglib/util/ConstantsUtil.h", "w") {|file| file.puts replace}
    
    
    #清除group文件
    if !group.empty? then
        removeBuildPhaseFilesRecursively(target,group)
        group.clear()
    end
    
    #清楚Group文件夹下内容
    if !group_AIHelp.empty? then
        removeBuildPhaseFilesRecursively(target,group_AIHelp)
        group_AIHelp.clear()
    end
    
    if !group_AIHelp_H_M.empty? then
        removeBuildPhaseFilesRecursively(target,group_AIHelp_H_M)
        group_AIHelp_H_M.clear()
    end
    
    if !group_zhichi.empty? then
        removeBuildPhaseFilesRecursively(target,group_zhichi)
        group_zhichi.clear()
    end
    
    if !group_zhichi_H_M.empty? then
        removeBuildPhaseFilesRecursively(target,group_zhichi_H_M)
        group_zhichi_H_M.clear()
    end
    
    if !group_QYAccessLayer.empty? then
        removeBuildPhaseFilesRecursively(target,group_QYAccessLayer)
        group_QYAccessLayer.clear()
    end
    
    
    
    ##获取所有静态库文件引用
    framework_ref_list = target.frameworks_build_phases.files_references
    #puts "#{framework_ref_list} : xzw"
    
    for file_ref_temp in framework_ref_list
        if file_ref_temp then
            if file_ref_temp.to_s.end_with?("ElvaChatServiceSDK.framework","MQTTFramework.framework","SobotKit.framework") then
                target.frameworks_build_phases.remove_file_reference(file_ref_temp)
            end
            elsif !file_ref_temp then
            target.frameworks_build_phases.remove_file_reference(file_ref_temp)
        end
    end
    
    
    #递归添加.h .m  .bundle
    
    puts "七鱼开始..."
    
    fileName = 'qiyuSDK'
    filePath = File.join(group.real_path, fileName)
    addFilesToGroup(target, group, filePath, fileName)
    
    fileName_QYAccessLayer = 'QYSDK'
    filePath_QYAccessLayer = File.join(group_QYAccessLayer.real_path, fileName_QYAccessLayer)
    addFilesToGroup(target, group_QYAccessLayer, filePath_QYAccessLayer, fileName_QYAccessLayer)
    
    
    puts "七鱼结束..."
    
    #设置索引 FRAMEWORK_SEARCH_PATHS
    target.build_configurations.each do |config|
        config.build_settings["LIBRARY_SEARCH_PATHS"] = ["$(inherited)","$(PROJECT_DIR)/leitinglib/framework/qiyuSDK"]
    end
    
    
    project.save
    
    
    #!/usr/bin/env ruby
    require 'xcodeproj'
    
    #打开项目工程
    puts("------------开始处理数据统计SDK------------")
    #接收工程目录参数
    project_path = ARGV.at(0)
    
    #接收使用数据统计SDK参数 1:Adjust,2:Firebase,3:Kochava,4:Adjust&Firebase
    dataType = ARGV.at(1)
    
    project = Xcodeproj::Project.open(project_path+".xcodeproj")
    target = project.targets.first
    
    #找到要插入的group(参数中的true表示如果找不到group,就创建一个group)
    
    group_Adjust = project.main_group.find_subpath('leitinglib/framework/AdjustSDK',true)
    group_Adjust.set_source_tree('<group>')
    
    group_Firebase = project.main_group.find_subpath('leitinglib/framework/FirebaseSDK',true)
    group_Firebase.set_source_tree('<group>')
    
    group_Kochava = project.main_group.find_subpath('leitinglib/framework/libKochavaTrackeriOSGK',true)
    group_Kochava.set_source_tree('<group>')
    
    group_Log = project.main_group.find_subpath('leitinglib/feature/Log',true)
    group_Log.set_source_tree('<group>')
    
    
    #递归添加索引
    def addFilesToGroup(aTarget, aGroup, filePath, fileName)
        if File.directory? filePath
            # 当前文件为目录
            Dir.foreach(filePath) do |file|
                if file.to_s.end_with?(".bundle")
                    #bundle文件属于目录,直接添加引用
                    puts("添加"+file)
                    file_ref = aGroup.new_reference(File.join(filePath, file))
                    aTarget.add_resources([file_ref])
                elsif file !="." && file !=".."then
                    subPath = File.join(filePath, file)
                    
                    if File.directory? subPath
                        if subPath.to_s.end_with?(".framework")
                            puts "添加#{subPath}"
                            file_ref = aGroup.new_reference(subPath)
                            aTarget.frameworks_build_phases.add_file_reference(file_ref)
                        else
                            #子文件也属于目录,添加新的group
                            newGroup = aGroup.find_subpath(file,true)
                            #递归添加索引
                            addFilesToGroup(aTarget, newGroup, subPath, fileName+"/"+file)
                        end
                    else
                        #递归添加索引
                        addFilesToGroup(aTarget, aGroup, subPath, fileName+"/"+file )
                    end
                end
            end
        else
        #puts("fileName=",fileName)
            # 过滤目录和.DS_Store文件
            if fileName.to_s.end_with?(".h") || fileName.to_s.end_with?(".m")
                #h或m文件
                puts("添加"+fileName)
                file_ref = aGroup.new_reference(fileName)
                aTarget.add_file_references([file_ref])
            elsif fileName.to_s.end_with?(".a")
                #.a库
                puts("添加"+fileName)
                file_ref = aGroup.new_reference(fileName)
                aTarget.frameworks_build_phases.add_file_reference(file_ref)
            end
        end
    end
    
    
    #删除索引
    def removeBuildPhaseFilesRecursively(aTarget, aGroup)
        aGroup.files.each do |file|
            if file.real_path.to_s.end_with?(".m", ".mm", ".cpp") then
                aTarget.source_build_phase.remove_file_reference(file)
            elsif file.real_path.to_s.end_with?(".bundle") then
                aTarget.resources_build_phase.remove_file_reference(file)
            elsif file.real_path.to_s.end_with?(".a") then
                aTarget.frameworks_build_phases.remove_file_reference(file)
            end
        end
        
        aGroup.groups.each do |group|
            removeBuildPhaseFilesRecursively(aTarget, group)
        end
    end
    
    
    #修改leitinglib/util/ConstantsUtil.h文件中宏定义
    puts("------------开始修改宏定义------------")
    if dataType == "1"
        text = File.read(project_path+"/util/ConstantsUtil.h")
        replace = text.gsub("USE_FIREBASE","USE_ADJUST")
        replace = replace.gsub("USE_KOCHAVA","USE_ADJUST")
        replace = replace.gsub("USE_BOTH_ADJUST_FIREBASE","USE_ADJUST")
        puts("------------修改为使用USE_ADJUST------------")
    elsif dataType == "2"
        text = File.read(project_path+"/util/ConstantsUtil.h")
        replace = text.gsub("USE_ADJUST","USE_FIREBASE")
        replace = replace.gsub("USE_KOCHAVA","USE_FIREBASE")
        replace = replace.gsub("USE_BOTH_ADJUST_FIREBASE","USE_FIREBASE")
        puts("------------修改为使用USE_FIREBASE------------")
    elsif dataType == "3"
        text = File.read(project_path+"/util/ConstantsUtil.h")
        replace = text.gsub("USE_ADJUST","USE_KOCHAVA")
        replace = replace.gsub("USE_FIREBASE","USE_KOCHAVA")
        replace = replace.gsub("USE_BOTH_ADJUST_FIREBASE","USE_KOCHAVA")
        puts("------------修改为使用USE_KOCHAVA------------")
    elsif dataType == "4"
        text = File.read(project_path+"/util/ConstantsUtil.h")
        replace = text.gsub("USE_ADJUST","USE_BOTH_ADJUST_FIREBASE")
        replace = replace.gsub("USE_FIREBASE","USE_BOTH_ADJUST_FIREBASE")
        replace = replace.gsub("USE_KOCHAVA","USE_BOTH_ADJUST_FIREBASE")
        puts("------------修改为使用USE_BOTH_ADJUST_FIREBASE------------")
    end
    File.open(project_path+"/util/ConstantsUtil.h", "w") {|file| file.puts replace}
    puts("------------修改宏定义结束------------")
    
    
    
    #清除Adjust库文件
    if !group_Adjust.empty? then
        puts("------------开始删除Adjust库文件------------")
        removeBuildPhaseFilesRecursively(target,group_Adjust)
        group_Adjust.clear()
        puts("------------删除Adjust库文件结束------------")
    end
    
    #清除Firebase库文件
    if !group_Firebase.empty? then
        puts("------------开始删除Firebase库文件------------")
        removeBuildPhaseFilesRecursively(target,group_Firebase)
        group_Firebase.clear()
        puts("------------删除Firebase库文件结束------------")
    end
    
    #清除Kochava库文件
    if !group_Kochava.empty? then
        puts("------------开始删除Kochava库文件------------")
        removeBuildPhaseFilesRecursively(target,group_Kochava)
        group_Kochava.clear()
        puts("------------删除Kochava库文件结束------------")
    end
    
    
    
    #清除feature/Log文件夹下的AdjustManage文件
    puts("------------开始删除feature/Log/AdjustManage文件------------")
    adjust_h_ref = group_Log.find_file_by_path('AdjustManage.h')
    adjust_m_ref = group_Log.find_file_by_path('AdjustManage.m')
    
    target.source_build_phase.remove_file_reference([adjust_h_ref])
    target.headers_build_phase.remove_file_reference([adjust_h_ref])
    
    target.source_build_phase.remove_file_reference([adjust_m_ref])
    target.headers_build_phase.remove_file_reference([adjust_m_ref])
    
    if !adjust_h_ref.nil?
        adjust_h_ref.remove_from_project
    end
    
    if !adjust_m_ref.nil?
        adjust_m_ref.remove_from_project
    end
    puts("------------删除feature/Log/AdjustManage文件结束------------")
    
    
    #清除feature/Log文件夹下的FirebaseMnage文件
    puts("------------开始删除feature/Log/FirebaseMnage文件------------")
    firebase_h_ref = group_Log.find_file_by_path('FirebaseManage.h')
    firebase_m_ref = group_Log.find_file_by_path('FirebaseManage.m')
    
    target.source_build_phase.remove_file_reference([firebase_h_ref])
    target.headers_build_phase.remove_file_reference([firebase_h_ref])
    
    target.source_build_phase.remove_file_reference([firebase_m_ref])
    target.headers_build_phase.remove_file_reference([firebase_m_ref])
    
    if !firebase_h_ref.nil?
        firebase_h_ref.remove_from_project
    end
    
    if !firebase_m_ref.nil?
        firebase_m_ref.remove_from_project
    end
    puts("------------删除feature/Log/FirebaseMnage文件结束------------")
    
    
    #清除feature/Log文件夹下的KochavaManage文件
    puts("------------开始删除feature/Log/KochavaManage文件------------")
    kochava_h_ref = group_Log.find_file_by_path('KochavaManage.h')
    kochava_m_ref = group_Log.find_file_by_path('KochavaManage.m')
    
    target.source_build_phase.remove_file_reference([kochava_h_ref])
    target.headers_build_phase.remove_file_reference([kochava_h_ref])
    
    target.source_build_phase.remove_file_reference([kochava_m_ref])
    target.headers_build_phase.remove_file_reference([kochava_m_ref])
    
    if !kochava_h_ref.nil?
        kochava_h_ref.remove_from_project
    end
    
    if !kochava_m_ref.nil?
        kochava_m_ref.remove_from_project
    end
    puts("------------删除feature/Log/KochavaManage文件结束------------")
    
    
    
    puts("------------开始删除build_phases中的引用------------")
    ##获取所有静态库文件引用
    framework_ref_list = target.frameworks_build_phases.files_references
    for file_ref_temp in framework_ref_list
        if file_ref_temp then
            if file_ref_temp.to_s.end_with?("AdjustSdk.framework","FIRAnalyticsConnector.framework","FirebaseABTesting.framework","FirebaseAnalytics.framework","FirebaseCore.framework","FirebaseCoreDiagnostics.framework","FirebaseInstanceID.framework","FirebaseMessaging.framework","FirebaseRemoteConfig.framework","GoogleAppMeasurement.framework","GoogleDataTransport.framework","GoogleDataTransportCCTSupport.framework","GoogleUtilities.framework","nanopb.framework","Protobuf.framework") then
                target.frameworks_build_phases.remove_file_reference(file_ref_temp)
            end
        elsif !file_ref_temp then
            target.frameworks_build_phases.remove_file_reference(file_ref_temp)
        end
    end
    puts("------------删除build_phases中的引用结束------------")
    
    
    #递归添加.h .m  .bundle
    if dataType == "1"
        puts "------------开始添加Adjust库和封装文件------------"
        fileName = 'AdjustSDK'
        filePath = File.join(group_Adjust.real_path, fileName)
        addFilesToGroup(target, group_Adjust, filePath, fileName)
        #添加AdjustManage文件
        adjust_h_ref = group_Log.new_reference('AdjustManage.h')
        adjust_m_ref = group_Log.new_reference('AdjustManage.m')
    
        target.add_file_references([adjust_h_ref])
        target.add_file_references([adjust_m_ref])
        puts "------------添加Adjust库和封装文件结束------------"
    elsif dataType == "2"
          puts "------------开始添加Firebase库和封装文件------------"
          fileName = 'FirebaseSDK'
          filePath = File.join(group_Firebase.real_path, fileName)
          addFilesToGroup(target, group_Firebase, filePath, fileName)
          #添加FirebaseManage文件
          firebase_h_ref = group_Log.new_reference('FirebaseManage.h')
          firebase_m_ref = group_Log.new_reference('FirebaseManage.m')
    
          target.add_file_references([firebase_h_ref])
          target.add_file_references([firebase_m_ref])
          puts "------------添加Firebase库和封装文件结束------------"
    elsif dataType == "3"
          puts "------------开始添加kochava------------"
          #递归添加 .bundle .framework
          fileName = 'libKochavaTrackeriOSGK'
          filePath = File.join(group_Kochava.real_path, fileName)
          addFilesToGroup(target, group_Kochava, filePath, fileName)
          
          #添加KochavaManage文件
          kochava_h_ref = group_Log.new_reference('KochavaManage.h')
          kochava_m_ref = group_Log.new_reference('KochavaManage.m')
    
          target.add_file_references([kochava_h_ref])
          target.add_file_references([kochava_m_ref])
          puts "------------添加kochava结束------------"
    elsif dataType == "4"
           puts "------------开始添加USE_BOTH_ADJUST_FIREBASE库和封装文件------------"
           fileName = 'AdjustSDK'
           filePath = File.join(group_Adjust.real_path, fileName)
           addFilesToGroup(target, group_Adjust, filePath, fileName)
           #添加AdjustManage文件
           adjust_h_ref = group_Log.new_reference('AdjustManage.h')
           adjust_m_ref = group_Log.new_reference('AdjustManage.m')
    
           target.add_file_references([adjust_h_ref])
           target.add_file_references([adjust_m_ref])
          
          
           fileName1 = 'FirebaseSDK'
           filePath1 = File.join(group_Firebase.real_path, fileName1)
           addFilesToGroup(target, group_Firebase, filePath1, fileName1)
           #添加FirebaseManage文件
           firebase_h_ref = group_Log.new_reference('FirebaseManage.h')
           firebase_m_ref = group_Log.new_reference('FirebaseManage.m')
    
           target.add_file_references([firebase_h_ref])
           target.add_file_references([firebase_m_ref])
           puts "------------添加USE_BOTH_ADJUST_FIREBASE库和封装文件结束------------"
    end
    
    puts "------------开始设置路径------------"
    #设置索引 FRAMEWORK_SEARCH_PATHS
    if dataType == "1"
        target.build_configurations.each do |config|
            puts "FRAMEWORK_SEARCH_PATHS 添加 $(PROJECT_DIR)/leitinglib/framework/AdjustSDK"
            config.build_settings["FRAMEWORK_SEARCH_PATHS"] << "$(PROJECT_DIR)/leitinglib/framework/AdjustSDK"
            config.build_settings["FRAMEWORK_SEARCH_PATHS"].uniq!
        end
    elsif dataType == "2"
        target.build_configurations.each do |config|
             puts "FRAMEWORK_SEARCH_PATHS 添加 $(PROJECT_DIR)/leitinglib/framework/FirebaseSDK"
             config.build_settings["FRAMEWORK_SEARCH_PATHS"] << "$(PROJECT_DIR)/leitinglib/framework/FirebaseSDK"
             config.build_settings["FRAMEWORK_SEARCH_PATHS"].uniq!
        end
    elsif dataType == "3"
         target.build_configurations.each do |config|
            puts "LIBRARY_SEARCH_PATHS 添加 $(PROJECT_DIR)/leitinglib/framework/libKochavaTrackeriOSGK"
            config.build_settings["LIBRARY_SEARCH_PATHS"] << "$(PROJECT_DIR)/leitinglib/framework/libKochavaTrackeriOSGK"
            config.build_settings["LIBRARY_SEARCH_PATHS"].uniq!
        end
    elsif dataType == "4"
          target.build_configurations.each do |config|
             puts "FRAMEWORK_SEARCH_PATHS 添加 $(PROJECT_DIR)/leitinglib/framework/AdjustSDK"
             config.build_settings["FRAMEWORK_SEARCH_PATHS"] << "$(PROJECT_DIR)/leitinglib/framework/AdjustSDK"
             puts "FRAMEWORK_SEARCH_PATHS 添加 $(PROJECT_DIR)/leitinglib/framework/FirebaseSDK"
             config.build_settings["FRAMEWORK_SEARCH_PATHS"] << "$(PROJECT_DIR)/leitinglib/framework/FirebaseSDK"
             config.build_settings["LIBRARY_SEARCH_PATHS"].uniq!
         end
    end
    
    puts "------------设置路径结束------------"
    
    project.save
    
    puts("------------处理数据统计SDK结束------------")
    
    
    //
    //  ViewController.m
    //  SDKPackageProject
    //
    //  Created by zhengj on 2019/9/19.
    //  Copyright © 2019 zhengj. All rights reserved.
    //
    
    #import "ViewController.h"
    #import "Contants.h"
    
    @interface ViewController()<NSComboBoxDataSource>
    
    @property (nonatomic, strong) NSTextField *sdkPathText;         //SDK路径文本
    @property (nonatomic, strong) NSButton *sdkPathButton;          //SDK路径选择按钮
    
    @property (nonatomic, strong) NSTextField *frameText;           //文本框
    
    @property (nonatomic, strong) NSTextField *typeText;            //sdk版本文本框
    @property (nonatomic, strong) NSPopUpButton *typePopButton;     //sdk版本下拉选择框(国内、海外)
    
    @property (nonatomic, strong) NSTextField *platformText;        //打包平台文本
    @property (nonatomic, strong) NSPopUpButton *platformPopButton; //打包平台下拉选择框
    
    @property (nonatomic, strong) NSTextField *customServiceText;   //客服工具文本(国内)
    @property (nonatomic, strong) NSPopUpButton *popButton;         //客服工具下拉选择框(国内)
    
    @property (nonatomic, strong) NSTextField *adServiceText;       //广告工具文本(国内)
    @property (nonatomic, strong) NSPopUpButton *adPopButton;       //广告工具下拉选择框(国内)
    
    @property (nonatomic, strong) NSTextField *rpsdkText;           //实人认证sdk文本(国内)
    @property (nonatomic, strong) NSPopUpButton *rpPopButton;       //实人认证下拉选择框(国内)
    
    @property (nonatomic, strong) NSTextField *dataText;            //数据统计sdk文本(海外)
    @property (nonatomic, strong) NSPopUpButton *dataPopButton;     //数据统计下拉选择框(海外)
    
    @property (nonatomic, strong) NSScrollView *outPutScrollView;   //结果输出ScrollView
    @property (nonatomic, strong) NSTextView *outPutTextView;       //结果输出文本框
    
    @property (nonatomic, strong) NSButton *packageButton;          //打包按钮
    @property (nonatomic, strong) NSButton *cleanButton;            //清除输出记录
    @property (nonatomic, strong) id observer;
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        self.view.window.title = @"SDK打包工具";
        self.view.frame = NSMakeRect(0, 0, 900, 700);
        self.view.wantsLayer = YES;
        self.view.layer.backgroundColor = BACK_COLOR.CGColor;
        [self.view setNeedsDisplay:YES];
        
        [self.view addSubview:self.sdkPathButton];
        [self.view addSubview:self.sdkPathText];
        [self.view addSubview:self.frameText];
        [self.view addSubview:self.typeText];
        [self.view addSubview:self.typePopButton];
        [self.view addSubview:self.dataText];
        [self.view addSubview:self.dataPopButton];
        [self.view addSubview:self.platformText];
        [self.view addSubview:self.platformPopButton];
        
        //客服
        [self.view addSubview:self.customServiceText];
        [self.view addSubview:self.popButton];
        
        //广告
        [self.view addSubview:self.adServiceText];
        [self.view addSubview:self.adPopButton];
        
        [self.view addSubview:self.rpsdkText];
        [self.view addSubview:self.rpPopButton];
        [self.view addSubview:self.outPutScrollView];
        [self.view addSubview:self.packageButton];
        [self.view addSubview:self.cleanButton];
        
        [self.dataText setHidden:YES];
        [self.dataPopButton setHidden:YES];
        
        [self.platformText setHidden:YES];
        [self.platformPopButton setHidden:YES];
        [self.customServiceText setHidden:YES];
        [self.popButton setHidden:YES];
        [self.adServiceText setHidden:YES];
        [self.adPopButton setHidden:YES];
        [self.rpsdkText setHidden:YES];
        [self.rpPopButton setHidden:YES];
        
        //从本地获取上一次设置的sdk路径
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        NSString *defaultPath = [userDefaults objectForKey:DEFAULT_PATH];
        if (defaultPath != nil) {
            self.sdkPathText.stringValue = defaultPath;
        }
    }
    
    //选择SDK路径
    - (void)selectSDKPath {
        NSOpenPanel *panel = [NSOpenPanel openPanel];
        [panel setAllowsMultipleSelection:NO];
        [panel setCanChooseDirectories:YES];
        [panel setCanChooseFiles:YES];
        [panel setTitle:@"选择文件"];
        [panel setPrompt:@"确定"];
        
        //从本地获取配置路径,并设置为打开文件夹的路径
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        NSString *defaultPath = [userDefaults objectForKey:DEFAULT_PATH];
        if (defaultPath != nil) {
            [panel setDirectoryURL:[NSURL URLWithString:defaultPath]];
        }
        
        [panel beginSheetModalForWindow:[self.view window] completionHandler:^(NSModalResponse returnCode) {
            if (returnCode == 1) {
                //点击确定以后
                NSString *path = [panel.URLs.firstObject path];
                NSLog(@"sdk path : %@",path);
                self.sdkPathText.stringValue = path;
                [userDefaults setObject:path forKey:DEFAULT_PATH];
            }
        }];
    }
    
    //显示对应的选项
    - (void)handlePopBtn:(NSPopUpButton *)popBtn {
        // 选中item 的索引
        NSLog(@"%ld", (long)popBtn.indexOfSelectedItem);
        popBtn.title = popBtn.selectedItem.title;
        
        //sdk版本选择
        if (popBtn.tag == 10001) {
            
            [self.platformText setHidden:NO];
            [self.platformPopButton setHidden:NO];
            
            //国内
            if (popBtn.indexOfSelectedItem == 1) {
               
                self.frameText.frame = NSMakeRect(26, 546, 844, 110);
                self.outPutScrollView.frame = NSMakeRect(30, 60, 840, 480);
                self.outPutTextView.frame = NSMakeRect(10, 0, 840, 480);
                
                //客服工具
                [self.customServiceText setHidden:NO];
                [self.popButton setHidden:NO];
                
                //广告工具
                [self.adServiceText setHidden:NO];
                [self.adPopButton setHidden:NO];
                
                
                //实人认证工具
                [self.rpsdkText setHidden:NO];
                [self.rpPopButton setHidden:NO];
                
                //隐藏数据统计
                [self.dataText setHidden:YES];
                [self.dataPopButton setHidden:YES];
                
                
                //支持平台,显示
                self.platformText.frame = NSMakeRect(500, 573, 120, 30);
                self.platformPopButton.frame = NSMakeRect(560, 580, 120, 30);
                
            }
            else {
                
                //国外
                 self.frameText.frame = NSMakeRect(26, 576, 844, 80);
                 self.outPutScrollView.frame = NSMakeRect(30, 60, 840, 500);
                 self.outPutTextView.frame = NSMakeRect(10, 0, 840, 500);
                
                
                //隐藏客服工具
                [self.customServiceText setHidden:YES];
                [self.popButton setHidden:YES];
                
                
                //广告工具
                [self.adServiceText setHidden:YES];
                [self.adPopButton setHidden:YES];
                
                
                //隐藏人脸识别认证
                [self.rpsdkText setHidden:YES];
                [self.rpPopButton setHidden:YES];
                
                //显示数据统计
                [self.dataText setHidden:NO];
                [self.dataPopButton setHidden:NO];
                
                
                //支持平台,显示
                self.platformText.frame = NSMakeRect(250, 573, 120, 30);
                self.platformPopButton.frame = NSMakeRect(320, 580, 120, 30);
                
            }
        }
    }
    
    //开始打包
    - (void)package {
        //检查sdk路径
        if (self.sdkPathText.stringValue.length == 0) {
            [self showPopover:self.packageButton withContens:@"请选择SDK路径"];
            return;
        }
        
        //检查SDK版本
        if (self.typePopButton.indexOfSelectedItem == -1) {
            [self showPopover:self.packageButton withContens:@"请选择SDK版本"];
            return;
        }
        
        //检查客服工具
        if (self.typePopButton.indexOfSelectedItem == 1 &&
            self.popButton.indexOfSelectedItem == -1) {
            [self showPopover:self.packageButton withContens:@"请选择客服工具"];
            return;
        }
        
        //检查广告工具
          if (self.adPopButton.indexOfSelectedItem == 1 &&
              self.adPopButton.indexOfSelectedItem == -1) {
              [self showPopover:self.packageButton withContens:@"请选择广告工具"];
              return;
          }
        
        //检查实人认证SDK
        if (self.typePopButton.indexOfSelectedItem == 1 &&
            self.rpPopButton.indexOfSelectedItem == -1) {
            [self showPopover:self.packageButton withContens:@"请选择实人认证工具"];
            return;
        }
        
        //检查数据统计SDK
        if (self.typePopButton.indexOfSelectedItem == 2 &&
            self.dataPopButton.indexOfSelectedItem == -1) {
            [self showPopover:self.packageButton withContens:@"请选择数据统计SDK"];
            return;
        }
        
        
        //检查数据统计SDK
        if (self.platformPopButton.indexOfSelectedItem == -1) {
            [self showPopover:self.packageButton withContens:@"请选择支持平台"];
            return;
        }
        
        self.outPutTextView.string = [self.outPutTextView.string stringByAppendingString:@"------------开始打包--------------"];
        
        if (self.typePopButton.indexOfSelectedItem == 1) {
            //国内sdk
            NSLog(@"------------当前为国内sdk------------");
            NSString *customFileName;
            if (self.popButton.indexOfSelectedItem == 1) {
                //使用七鱼
                customFileName = @"QiYu.rb";
            }
            else if (self.popButton.indexOfSelectedItem == 2) {
                //使用Aihelp
                customFileName = @"AIHelp.rb";
            }
            else if (self.popButton.indexOfSelectedItem == 3) {
                //使用Aihelp
                customFileName = @"ZhiChi.rb";
            }
            
            //客服工具配置命令
            NSString *cmd1 = [NSString stringWithFormat:@"cd %@;ruby %@ %@/leitinglib",[self getCurrentAppPath], customFileName, self.sdkPathText.stringValue];
            NSLog(@"执行客服工具配置命令 %@", cmd1);
    
            NSArray *arguments1 = [NSArray arrayWithObjects: @"-c",cmd1, nil];
            [self excuteCMD:arguments1];
            
            //是否使用实人认证SDK
            NSString *rpFileName = @"RPSDK.rb";
            NSString *isUse = @"0";
            if (self.rpPopButton.indexOfSelectedItem == 1) {
                //不使用
                isUse = @"0";
            }
            else if (self.rpPopButton.indexOfSelectedItem == 2) {
                //使用阿里实人认证sdk
                isUse = @"1";
            }
            
            //实人认证配置命令
            NSString *cmd2 = [NSString stringWithFormat:@"cd %@;ruby %@ %@/leitinglib %@",[self getCurrentAppPath], rpFileName, self.sdkPathText.stringValue, isUse];
            NSLog(@"执行实人认证配置命令 %@", cmd2);
            
            NSArray *arguments2 = [NSArray arrayWithObjects: @"-c",cmd2, nil];
            [self excuteCMD:arguments2];
            
            //是否使用广告工具
            NSString *adFileName;
            if (self.adPopButton.indexOfSelectedItem == 1) {
                //使用七鱼
                adFileName = @"remove_ads.rb";
                
            }else if (self.adPopButton.indexOfSelectedItem == 2) {
                //使用Aihelp
                adFileName = @"toutiao.rb";
            }
            else if (self.adPopButton.indexOfSelectedItem == 3) {
                //使用Aihelp
                adFileName = @"upltv.rb";
            }
                //客服工具配置命令
            NSString *cmd3 = [NSString stringWithFormat:@"cd %@;ruby %@ %@/leitinglib",[self getCurrentAppPath], adFileName, self.sdkPathText.stringValue];
            NSLog(@"执行广告工具配置命令 %@", cmd3);
    
            NSArray *arguments3 = [NSArray arrayWithObjects: @"-c",cmd3, nil];
            [self excuteCMD:arguments3];
            
        }
        else {
            //海外SDK
            NSLog(@"------------当前为海外sdk------------");
            
            //使用数据统计SDK(海外)
            NSString *dataFileName = @"DataSDK.rb";
            NSString *dataType = @"1";
            if (self.dataPopButton.indexOfSelectedItem == 1) {
                //使用Adjust
                dataType = @"1";
            }
            else if (self.dataPopButton.indexOfSelectedItem == 2) {
                //使用Firebase
                dataType = @"2";
            }
            else if (self.dataPopButton.indexOfSelectedItem == 3) {
                //使用kochava
                dataType = @"3";
            }
            else if (self.dataPopButton.indexOfSelectedItem == 4) {
               //使用Adjust&Firebase
               dataType = @"4";
            }
            
            NSString *cmd1 = [NSString stringWithFormat:@"cd %@;ruby %@ %@/leitinglib %@",[self getCurrentAppPath], dataFileName, self.sdkPathText.stringValue, dataType];
            NSLog(@"执行数据统计SDK配置命令 %@", cmd1);
            
            NSArray *arguments1 = [NSArray arrayWithObjects: @"-c",cmd1, nil];
            [self excuteCMD:arguments1];
            
        }
        
        //打包命令
        NSString *pcmd = [NSString stringWithFormat:@"cd %@;./Script.sh %@/leitinglib.xcodeproj",[self getCurrentAppPath], self.sdkPathText.stringValue];
        NSLog(@"执行打包命令 %@", pcmd);
        
        NSArray *arguments = [NSArray arrayWithObjects: @"-c",pcmd, nil];
        [self excuteCMD:arguments];
    }
    
    //执行命令
    - (void)excuteCMD:(NSArray *)arguments {
        //初始化并配置task
        NSTask *task;
        task = [[NSTask alloc] init];
        [task setLaunchPath: @"/bin/bash"];
        
        [task setArguments: arguments];
        
        //设置标准输出管道
        NSPipe *pipe;
        pipe = [NSPipe pipe];
        [task setStandardOutput: pipe];
        
        //task结束回调
        [task setTerminationHandler: ^(NSTask *t) {
            //移除通知
            [[NSNotificationCenter defaultCenter] removeObserver:self.observer name:NSFileHandleDataAvailableNotification object:[pipe fileHandleForReading]];
        }];
        
        //在后台线程等待数据和通
        [[pipe fileHandleForReading] waitForDataInBackgroundAndNotify];
        
        //接受到通知消息
        self.observer = [[NSNotificationCenter defaultCenter] addObserverForName:NSFileHandleDataAvailableNotification object:[pipe fileHandleForReading] queue:nil usingBlock:^(NSNotification * _Nonnull note) {
            //获取管道数据 转为字符串
            NSData *outputData = pipe.fileHandleForReading.availableData;
            NSString *string = [[NSString alloc] initWithData: outputData encoding: NSUTF8StringEncoding];
            if (string.length > 0) {
                NSLog(@"got\n%@", string);
                //在主线程处理UI
                dispatch_async(dispatch_get_main_queue(), ^{
                    self.outPutTextView.string = [self.outPutTextView.string stringByAppendingString:[NSString stringWithFormat:@"\n%@",string]];
                    [self.outPutTextView scrollToEndOfDocument:self];
                });
            }
            
            //继续等待新数据和通知
            [[pipe fileHandleForReading] waitForDataInBackgroundAndNotify];
        }];
        
        [task launch];
        [task waitUntilExit];
    }
    
    - (void)cleanOutput {
        self.outPutTextView.string = @"";
    }
    
    //SDK路径选择按钮
    - (NSButton *)sdkPathButton {
        if (!_sdkPathButton) {
            _sdkPathButton = [[NSButton alloc] initWithFrame:NSMakeRect(30, 660, 90, 30)];
            [_sdkPathButton setBezelStyle:NSBezelStyleRoundRect];
            _sdkPathButton.layer.masksToBounds = YES;
            [_sdkPathButton setBordered:YES];
            [_sdkPathButton.layer setCornerRadius:16];
            [_sdkPathButton setTitle:@"选择SDK路径"];
            [_sdkPathButton setTarget:self];
            [_sdkPathButton setAction:@selector(selectSDKPath)];
        }
        return _sdkPathButton;
    }
    
    //SDK路径文本
    - (NSTextField *)sdkPathText {
        if (!_sdkPathText) {
            _sdkPathText = [[NSTextField alloc] initWithFrame:NSMakeRect(130, 654, 580, 30)];
            _sdkPathText.backgroundColor = [NSColor clearColor];
            _sdkPathText.textColor = [NSColor blackColor];
            _sdkPathText.stringValue = @"";
            [_sdkPathText setBordered:NO];
            [_sdkPathText setEditable:NO];
        }
        return _sdkPathText;
    }
    
    //文本框
    -(NSTextField *)frameText {
        if (!_frameText) {
            _frameText = [[NSTextField alloc] initWithFrame:NSMakeRect(26, 606, 844, 50)];
            _frameText.backgroundColor = [NSColor clearColor];
            _frameText.textColor = [NSColor blackColor];
            _frameText.stringValue = @"";
            [_frameText setBordered:YES];
            [_frameText setEditable:NO];
            _frameText.wantsLayer = YES;//必须设置,不然背景颜色显示不了
            _frameText.layer.cornerRadius = 5;
        }
        
        return _frameText;
    }
    
    //sdk版本文本框
    - (NSTextField *)typeText {
        if (!_typeText) {
            _typeText = [[NSTextField alloc] initWithFrame:NSMakeRect(30, 613, 120, 30)];
            _typeText.backgroundColor = [NSColor clearColor];
            _typeText.font = [NSFont systemFontOfSize:12];
            _typeText.textColor = [NSColor blackColor];
            _typeText.stringValue = @"SDK版本:";
            [_typeText setBordered:NO];
            [_typeText setEditable:NO];
        }
        return _typeText;
    }
    
    //sdk版本下拉选择框
    - (NSPopUpButton *)typePopButton {
        if (!_typePopButton) {
            _typePopButton = [[NSPopUpButton alloc] initWithFrame:CGRectMake(90, 620, 120, 30) pullsDown:YES];
            [_typePopButton addItemWithTitle:@"请选择"];
            [_typePopButton setTag:10001];
            [_typePopButton addItemWithTitle:@"国内"];
            [_typePopButton addItemWithTitle:@"海外"];
            [_typePopButton setTarget:self];
            [_typePopButton setAction:@selector(handlePopBtn:)];
        }
        return _typePopButton;
    }
    
    //客服工具文本
    - (NSTextField *)dataText {
        if (!_dataText) {
            _dataText = [[NSTextField alloc] initWithFrame:NSMakeRect(30, 573, 120, 30)];
            _dataText.backgroundColor = [NSColor clearColor];
            _dataText.font = [NSFont systemFontOfSize:12];
            _dataText.textColor = [NSColor blackColor];
            _dataText.stringValue = @"数据统计:";
            [_dataText setBordered:NO];
            [_dataText setEditable:NO];
        }
        return _dataText;
    }
    
    //客服工具选择框
    - (NSPopUpButton *)dataPopButton {
        
        if (!_dataPopButton) {
            _dataPopButton = [[NSPopUpButton alloc] initWithFrame:CGRectMake(90, 580, 120, 30) pullsDown:YES];
            [_dataPopButton addItemWithTitle:@"请选择"];
            [_dataPopButton addItemWithTitle:@"Adjust"];
            [_dataPopButton addItemWithTitle:@"Firebase"];
            [_dataPopButton addItemWithTitle:@"Kochava"];
            [_dataPopButton addItemWithTitle:@"Adjust&Firebase"];
            [_dataPopButton setTarget:self];
            [_dataPopButton setAction:@selector(handlePopBtn:)];
        }
        return _dataPopButton;
    }
    
    
    //客服工具文本
    - (NSTextField *)customServiceText {
        if (!_customServiceText) {
            _customServiceText = [[NSTextField alloc] initWithFrame:NSMakeRect(30, 573, 120, 30)];
            _customServiceText.backgroundColor = [NSColor clearColor];
            _customServiceText.font = [NSFont systemFontOfSize:12];
            _customServiceText.textColor = [NSColor blackColor];
            _customServiceText.stringValue = @"客服工具:";
            [_customServiceText setBordered:NO];
            [_customServiceText setEditable:NO];
        }
        return _customServiceText;
    }
    
    //客服工具选择框
    - (NSPopUpButton *)popButton {
        if (!_popButton) {
            _popButton = [[NSPopUpButton alloc] initWithFrame:CGRectMake(90, 580, 120, 30) pullsDown:YES];
            [_popButton addItemWithTitle:@"请选择"];
            [_popButton addItemWithTitle:@"七鱼"];
            [_popButton addItemWithTitle:@"Aihelp"];
            [_popButton addItemWithTitle:@"智齿"];
            [_popButton setTarget:self];
            [_popButton setAction:@selector(handlePopBtn:)];
        }
        return _popButton;
    }
    
    //广告工具文本
    - (NSTextField *)adServiceText {
        if (!_adServiceText) {
            _adServiceText = [[NSTextField alloc] initWithFrame:NSMakeRect(30, 543, 120, 30)];
            _adServiceText.backgroundColor = [NSColor clearColor];
            _adServiceText.font = [NSFont systemFontOfSize:12];
            _adServiceText.textColor = [NSColor blackColor];
            _adServiceText.stringValue = @"广告工具:";
            [_adServiceText setBordered:NO];
            [_adServiceText setEditable:NO];
        }
        return _adServiceText;
    }
    
    //广告工具选择框
    - (NSPopUpButton *)adPopButton {
        if (!_adPopButton) {
            _adPopButton = [[NSPopUpButton alloc] initWithFrame:CGRectMake(90, 550, 120, 30) pullsDown:YES];
            [_adPopButton addItemWithTitle:@"请选择"];
            [_adPopButton addItemWithTitle:@"不使用"];
            [_adPopButton addItemWithTitle:@"穿山甲"];
            [_adPopButton addItemWithTitle:@"upltv"];
            [_adPopButton setTarget:self];
            [_adPopButton setAction:@selector(handlePopBtn:)];
        }
        return _adPopButton;
    }
    
    //实人认证sdk文本
    - (NSTextField *)rpsdkText {
        if (!_rpsdkText) {
            _rpsdkText = [[NSTextField alloc] initWithFrame:NSMakeRect(230, 573, 120, 30)];
            _rpsdkText.backgroundColor = [NSColor clearColor];
            _rpsdkText.font = [NSFont systemFontOfSize:12];
            _rpsdkText.textColor = [NSColor blackColor];
            _rpsdkText.stringValue = @"实人认证工具:";
            [_rpsdkText setBordered:NO];
            [_rpsdkText setEditable:NO];
        }
        return _rpsdkText;
    }
    
    //实人认证下拉选择框
    - (NSPopUpButton *)rpPopButton {
        if (!_rpPopButton) {
            _rpPopButton = [[NSPopUpButton alloc] initWithFrame:CGRectMake(315, 580, 150, 30) pullsDown:YES];
            [_rpPopButton addItemWithTitle:@"请选择"];
            [_rpPopButton addItemWithTitle:@"不使用"];
            [_rpPopButton addItemWithTitle:@"阿里实人认证SDK"];
            [_rpPopButton setTarget:self];
            [_rpPopButton setAction:@selector(handlePopBtn:)];
        }
        return _rpPopButton;
    }
    
    //打包平台文本
    - (NSTextField *)platformText {
        if (!_platformText) {
            _platformText = [[NSTextField alloc] initWithFrame:NSMakeRect(500, 573, 120, 30)];
            _platformText.backgroundColor = [NSColor clearColor];
            _platformText.font = [NSFont systemFontOfSize:12];
            _platformText.textColor = [NSColor blackColor];
            _platformText.stringValue = @"支持平台:";
            [_platformText setBordered:NO];
            [_platformText setEditable:NO];
        }
        return _platformText;
    }
    
    //打包平台拉选择框
    - (NSPopUpButton *)platformPopButton {
        if (!_platformPopButton) {
            _platformPopButton = [[NSPopUpButton alloc] initWithFrame:CGRectMake(560, 580, 120, 30) pullsDown:YES];
            [_platformPopButton addItemWithTitle:@"请选择"];
            [_platformPopButton addItemWithTitle:@"真机"];
            [_platformPopButton addItemWithTitle:@"模拟器"];
            [_platformPopButton addItemWithTitle:@"合并"];
            [_platformPopButton setTarget:self];
            [_platformPopButton setAction:@selector(handlePopBtn:)];
        }
        return _platformPopButton;
    }
    
    //结果输出ScrollView
    - (NSScrollView *)outPutScrollView {
        if (!_outPutScrollView) {
            _outPutScrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect(30, 60, 840, 500)];
            _outPutScrollView.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
            _outPutScrollView.backgroundColor = OUTPUT_BACK_COLOR;
            [_outPutScrollView setHasVerticalScroller:YES];
            [_outPutScrollView setHasHorizontalScroller:NO];
            [_outPutScrollView setBorderType:NSLineBorder];
            
            //结果输出文本框
            _outPutTextView = [[NSTextView alloc] initWithFrame:NSMakeRect(10, 0, 840, 500)];
            _outPutTextView.backgroundColor = OUTPUT_BACK_COLOR;
            _outPutTextView.textColor = OUTPUT_TEXT_COLOR;
            _outPutTextView.font = [NSFont systemFontOfSize:13];
            _outPutTextView.allowsUndo = YES;
            _outPutTextView.richText = YES;
            _outPutTextView.editable = NO;
            _outPutTextView.automaticQuoteSubstitutionEnabled = NO;
            [_outPutTextView setVerticallyResizable:YES];
            [_outPutTextView setHorizontallyResizable:NO];
            [_outPutTextView setAutoresizingMask:NSViewWidthSizable];
            [_outPutScrollView setDocumentView:_outPutTextView];
        }
        
        return _outPutScrollView;
    }
    
    //打包按钮
    - (NSButton *)packageButton {
        if (!_packageButton) {
            _packageButton = [[NSButton alloc] initWithFrame:NSMakeRect(30, 10, 80, 30)];
            [_packageButton setBezelStyle:NSBezelStyleRoundRect];
            _packageButton.layer.masksToBounds = YES;
            [_packageButton setBordered:YES];
            [_packageButton.layer setCornerRadius:16];
            [_packageButton setTitle:@"开始打包"];
            [_packageButton setTarget:self];
            [_packageButton setAction:@selector(package)];
            
        }
        
        return _packageButton;
    }
    
    //清除输出记录
    - (NSButton *)cleanButton {
        if (!_cleanButton) {
            _cleanButton = [[NSButton alloc] initWithFrame:NSMakeRect(120, 10, 80, 30)];
            [_cleanButton setBezelStyle:NSBezelStyleRoundRect];
            _cleanButton.layer.masksToBounds = YES;
            [_cleanButton setBordered:YES];
            [_cleanButton.layer setCornerRadius:16];
            [_cleanButton setTitle:@"清除记录"];
            [_cleanButton setTarget:self];
            [_cleanButton setAction:@selector(cleanOutput)];
            
        }
        
        return _cleanButton;
    }
    
    //获取应用的资源路径
    -(NSString *) getCurrentAppPath
    {
        NSString* path = @"";
        NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
        NSRange range = [bundlePath rangeOfString:@"/" options:NSBackwardsSearch];
    
        if (range.location != NSNotFound)
        {
            path = [bundlePath substringToIndex:range.location];
            path = [path stringByAppendingFormat:@"%@",@"/SDKPackageProject.app/Contents/Resources"];
        }
        
        return path;
    }
    
    
    
    /*
     显示提示框
     
     @param button 点击按钮
     @param contents 提示内容
     
     */
    - (void) showPopover:(NSButton *)button withContens:(NSString *)contents {
        NSViewController* vc = [[NSStoryboard storyboardWithName:@"Main" bundle:nil] instantiateControllerWithIdentifier:@"Popover"];
        NSTextField *textField = (NSTextField *)[vc.view viewWithTag:0];
        textField.stringValue = contents;
        
        NSPopover *popover = [[NSPopover alloc] init];
        popover.contentViewController = vc;
        popover.behavior = NSPopoverBehaviorTransient;  //自动关闭popover
        
        [popover showRelativeToRect:button.bounds ofView:button preferredEdge:NSRectEdgeMinY];
    }
    
    
    - (void)setRepresentedObject:(id)representedObject {
        [super setRepresentedObject:representedObject];
    
        // Update the view, if already loaded.
    }
    
    
    @end
    
    

    相关文章

      网友评论

          本文标题:iOS 用脚本添加sdk库

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