Post

pod依赖大git库加载不成功的处理/pod根据电脑动态配置path本地依赖

前言

计划将一个framework从文件拖拽集成的方式改成pod依赖,但是文件所在的git库特别大,经常下载不成功,再加上私有库在内网git上,需要开VPN才能拉取代码,导致更新特别慢,于是使用pod的path文件依赖的方式,提前将依赖的framework所在的git库在本地更新好,这样pod时不必开VPN,而且速度也特别快,但是由于有多台开发机器,每台机器下载的framework库的位置不一样,导致podfile换一个人就要修改下path,这里研究下使用ruby语言的规则,将每台电脑都配置好,每个人pod时都使用预定好的路径,如果对应的路径不存在,则使用git依赖,Podfile具体实现如下:

完整demo:
https://github.com/eye1234456/PodSample.git
https://github.com/eye1234456/MyTestLibs.git

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# Uncomment the next line to define a global platform for your project
platform :ios, '13.0'

target 'MultiUserPathPod' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MultiUserPathPod
  #################引入hellosdk---begin---#######################
  #用户电脑用户名,调用whoami的名字
  user_name = ENV['USER']
  #不同用户名对应的key、sdk对应的本地路径 xxx.podspec
  user_hellosdk_localpath_dict =
  {
    "zhangsan" => "/Users/zhangsan/Documents/hellosdk",
    "lisi" => "/Users/lisi/Download/iOS/hellosdk",
    "wangwu" => "/Users/wangwu/Desktop/hellosdk",
  }
  #获取当前用户对应的路径
  hellodk_localpath = user_hellosdk_localpath_dict[user_name]
  if hellodk_localpath.nil?
    # 如果当前用户没有配置本地路径,则默认加载git上的路径
    puts "如果当前用户没有配置本地路径,则默认加载git上的路径" #打印说明
    hellodk_git_url = "https://github.com/eye1234456/MyTestLibs.git"
    # debug模式引入一个debug的sdk
    pod 'hellosdk_uat_static', :git => hellodk_git_url, :configurations => ['Debug']
    # release模式引入一个release的sdk
    pod 'hellosdk_release_static', :git => hellodk_git_url, :configurations => ['Release']
  else
    # 如果配置了本地path,则使用path的方式依赖
    puts "已经配置了本地路径,通过path的方式加载数据" #打印说明
    # debug模式引入一个debug的sdk
    pod 'hellosdk_uat_static', :path => hellodk_localpath, :configurations => ['Debug']
    # release模式引入一个release的sdk
    pod 'hellosdk_release_static', :path => hellodk_localpath, :configurations => ['Release']
  end
  #################引入hellosdk---end---#######################
  
  pod "AFNetworking"
  pod "Masonry"

  target 'MultiUserPathPodTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'MultiUserPathPodUITests' do
    # Pods for testing
  end

end


ruby常见问题及语法 Ruby和Cocoapods文章合集

1、获取当前用户:

1
2
3
4
//  on Unix\Mac
ENV["USER"]
//on Windows
ENV["USERNAME"] 

2、判断条件:https://www.tutorialspoint.com/ruby/ruby_if_else.htm

1
2
3
4
5
6
7
8
x = 1
if x > 2
   puts "x is greater than 2"
elsif x <= 2 and x!=0
   puts "x is 1"
else
   puts "I can't guess the number"
end

3、创建字典

1
2
3
4
5
6
7
8
9
#创建字典
mapa = 
{
    "xiaoming" => "i am xiaoming",
    "xiaowang" => "i am show",
    "laoli" => "hahah",
}
#读取字典
showtxt = mapa["laoli"]

4、判断是否为空
Ruby的.nil? .empty? .blank? .present?差别
ruby 非空判断

1
2
3
4
5
if str.nil? || str.empty?
    xxx
else
    yyy
end
This post is licensed under CC BY 4.0 by the author.