Module: ISandBoxHelper

Included in:
MockHelper
Defined in:
lib/common/isandbox_helper.rb

Overview

封装访问ios设备沙盒文件的核心模块

Defined Under Namespace

Classes: ISandboxOperator

Instance Method Summary collapse

Instance Method Details

#ipull_file(path) ⇒ Object

功能:

从非越狱iphone拉取一个文件

参数解释:

path: 文件在iphone上的路径和文件名

Example:

Example #1:



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/common/isandbox_helper.rb', line 73

def ipull_file(path)

    mount
    begin
        exec_cmd "cat #{path}" if File.file? path
    rescue
        p "error:#{$!} at:#{$@}"
    ensure
        umount
    end
end

#ipush_data(path, data, filename = '') ⇒ Object

功能:

向非越狱iphone推送一段内容

参数解释:

filename: 只是存储文件名,不带路径,目前mock路径是约定的data: 推送内容,一般是string,其他可以直接写入文件的写可以

Example:

Example #1:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/common/isandbox_helper.rb', line 24

def ipush_data(path, data, filename='')
    mount
    begin
        root_folder = $isandbox_operator.tmp_folder_name + path
        exec_cmd("mkdir #{root_folder}") unless File.directory? root_folder
        filename = root_folder + '/' + filename.to_s.split('/')[-1]
        # 去除可能的 //
        filename.sub(/\/\//, '/')
        File.open(filename, "w+") do |file|
            file.puts data
        end
    rescue
        p "error:#{$!} at:#{$@}"
    ensure
        umount
    end
end

#ipush_file(path, file) ⇒ Object

功能:

向非越狱iphone推送一个mock文件

参数解释:

filename: mock文件在MAC上的路径和文件名

Example:

Example #1:



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/common/isandbox_helper.rb', line 51

def ipush_file(path, file)
    mount
    begin
        path = $isandbox_operator.tmp_folder_name + path
        path.sub(/\/\//, '/')
        exec_cmd "cp #{file} #{path}"
    rescue
        p "error:#{$!} at:#{$@}"
    ensure
        umount
    end
end

#iremove_file(path) ⇒ Object

功能:

从非越狱iphone删除文件

参数解释:

  • path: 待删除文件或路径

Example:

Example #1:



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/common/isandbox_helper.rb', line 94

def iremove_file(path)
    mount
    begin
        path = $isandbox_operator.tmp_folder_name + path
        if File.directory? path
            path = path + '/*'
            path.sub(/\/\//, '/')
        end
        exec_cmd "rm -rf #{path}"
    rescue
        p "error:#{$!} at:#{$@}"
    ensure
        umount
    end
end