构建自己的iOS网络代理客户端Potatso

一些之前用的SS客户端都陆续下架了,心里有点方。正好朋友问我还有没有能用的,于是花了些时间构建一个自己的,这样就永远不会下架了

步骤如下:

一.安装Cocospods(如果已经安装好可以直接跳到第步)

1.1、更新gem:sudo gem update --system

1.2、删除gem源:gem sources --remove https://ruby.taobao.org/

1.3、修改gem源:gem sources -a https://gems.ruby-china.org

1.4、查看gem源是否是最新的:gem sources -l

1.5、升级cocoapods:sudo gem install -n /usr/local/bin cocoapods --pre

1.6、查看升级后的cocoapods版本:pod --version

 

二.构建Potatso

2.1、克隆代码:终端输入   git clone https://github.com/haxpor/Potatso.git

2.2、进入克隆的文件夹:cd Potatso  

2.3、更新子模块:git submodule update --init

2.4、安装依赖:打开Podfile,将内容替换为以下

source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'

platform :ios, '9.0'
use_frameworks!

def library
    pod 'KissXML', '~> 5.2.2'
    pod 'ICSMainFramework', :path => "./Library/ICSMainFramework/"
    pod 'MMWormhole', '~> 2.0.0'
    pod 'KeychainAccess'
    pod 'Crashlytics', '~> 3.10.7'
end

def tunnel
    pod 'MMWormhole', '~> 2.0.0'
end

def socket
    pod 'CocoaAsyncSocket', '~> 7.4.3'
end

def model
    pod 'RealmSwift', '~> 2.10.2'
end

target "Potatso" do
    pod 'Aspects', :path => "./Library/Aspects/"
    pod 'Cartography'
    pod 'AsyncSwift'
    pod 'SwiftColor'
    pod 'Appirater'
    pod 'Eureka'
    pod 'MBProgressHUD'
    pod 'CallbackURLKit', :path => "./Library/CallbackURLKit"
    pod 'ICDMaterialActivityIndicatorView', '~> 0.1.0'
    #pod 'Reveal-iOS-SDK', '~> 1.6.2', :configurations => ['Debug']
    pod 'ICSPullToRefresh', '~> 0.6'
    pod 'ISO8601DateFormatter', '~> 0.8'
    pod 'Alamofire'
    pod 'AlamofireObjectMapper', '~> 5.0'
    pod 'CocoaLumberjack/Swift', '~> 3.0.0'
    pod 'PSOperations'
    tunnel
    library
    socket
    model
end

target "PacketTunnel" do
    tunnel
    socket
end

target "PacketProcessor" do
    socket
end

target "TodayWidget" do
    pod 'Cartography'
    pod 'SwiftColor'
    library
    socket
    model
end

target "PotatsoLibrary" do
    library
    model
    # YAML-Framework 0.0.3 is not available in cocoapods so we install it from local using git submodule
    pod 'YAML-Framework', :path => "./Library/YAML-Framework"
end

target "PotatsoModel" do
    model
end

target "PotatsoLibraryTests" do
    library
end

,然后终端执行 pod install --verbose  (其实是改了source和几个库的版本,注释了Reveal库。为了方便全部贴出来)

2.5、使用XCode打开Potatso.xcworkspace;

2.6、更改Potatso及PacketTunnel、TodayWidget两个子项目的Bundle ID,例如本人分别改成:com.langgege.potatsocom.langgege.potatso.PacketTunnel和com.langgege.potatso.TodayWidget;(红色部分自己改,和其他人不同即可)

如下图,依次点击TARGETS中的Potatso、PacketTunnel、TodayWidget,修改他们的Bundle Identifier和team

构建自己的iOS网络代理客户端Potatso_第1张图片

 

2.7、更改Potatso及PacketTunnel、TodayWidget两个子项目Capabilities中的App Group,例如:”group.com.langgege.potatso”;

如下图,依次点击TARGETS中的Potatso、PacketTunnel、TodayWidget,选择Capabilities,拉到App Groups,删掉旧的,添加自己的groups

构建自己的iOS网络代理客户端Potatso_第2张图片

2.8、打开”PotatsoBase/Potatso.m”文件,将shareGroupIdentifier函数的返回值改成自己的group id;

2.9、将iPhone等iOS设备连接到电脑,目标选择新接入的设备,点击左上角的“build and run”按钮,Xcode会编译并安装App到设备上,然后启动

 

可能会出的问题:

1、Type ‘RLMIterator‘ does not conform to protocol ‘Sequence’

解决办法: 注销PotatsoMode/DBUtils.swift中的相关代码,具体是174-190和202-218行之间的代码;注销CloudSetManager.swift中27-31行的代码

2、Initializer for conditional binding must have Optional type, not ‘[Rule]’

解决办法: 将Potatso/Core/API.swift第65和256行的if和大括号去掉,如下:

//修改前
if let parsedObject = Mapper().mapArray(JSONArray: rulesJSON as! [[String : Any]]){
            rules.append(contentsOf: parsedObject)
}

//修改后
let parsedObject = Mapper().mapArray(JSONArray: rulesJSON as! [[String : Any]])
rules.append(contentsOf: parsedObject)

3、url: (7) Failed to connect to pyyaml.org port 80: Connection refused
错误描述: 执行pod install,前面一切顺利,到libYAML会出现问题:

Installing LibYAML (0.1.4)

[!] Error installing LibYAML
[!] /usr/bin/curl -f -L -o /var/folders/dj/ljst94xx47l7fn3wz4q9bwsw0000gn/T/d20180822-4467-1cotycr/file.tgz http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz –create-dirs –netrc-optional –retry 2

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 –:–:– –:–:– –:–:– 0
curl: (7) Failed to connect to pyyaml.org port 80: Connection refused

原因: libYAML的官网关闭了80端口访问

解决办法: 进入  /Users/你的用户名/.cocoapods/repos/master/Specs/5/b/9/LibYAML/0.1.4/

打开LibYAML.podspec.json”文件,将”http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz”改成“https://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz”

 

 

Potatso作者icodesign的文章:https://sspai.com/post/38909

本文大部分内容参考:https://tlanyan.me/build-potatso-problems-and-solutions/

你可能感兴趣的:(原创,IOS)