copy file from iOS(like iFunBox)

昨天浏览器组的同事跑来问了一个没有细想过的问题:没有越狱过的机器怎么通过USB使用脚本批处理iOS设备上的数据。

没有越狱意味着习惯使用的SSH不能用了。
只有使用libimobiledevice了,如下:

1.安装libimobiledevice,ifuse,ifuse依赖与libimobiledevice,
可以选择airport或brew安装
sudo brew update
sudo brew install libimobiledevice
sudo brew install ifuse

2.拷贝osxfusefs.fs 到/Library/Filesystems,并添加执行权限
sudo /bin/cp -RfX /usr/local/Cellar/osxfuse/2.6.2/Library/Filesystems/osxfusefs.fs /Library/Filesystems
sudo chmod +s /Library/Filesystems/osxfusefs.fs/Support/load_osxfusefs

3.终端输入ifuse -h,会打印出详细使用说明
挂载某个应用的沙盒到~/myapp:
app_bundleId=com.my.app
udid=xxxxxxxxxxxx
ifuse -u ${udid} --container ${app_bundleId} ~/myapp

4.关闭挂载:
umount ~/myapp

PS:itoos与iexploer等工具都是基于libimobiledevice库进行开发的,iOS 6.x的越狱也用到了此库,更为重要的是appium也依赖于它,如果大家有安装过appium环境那么可以查看下build/libimobiledevice-macosx/,有许多可执行的unix文件
idevice_id
idevicebackup
idevicebackup2
idevicedate
idevicedebugserverproxy
idevicediagnostics
ideviceenterrecovery
ideviceimagemounter
ideviceinfo
idevicepair
ideviceprovision
idevicescreenshot
idevicesyslog
可以直接使用这些命令行工具,例如:
idevice_id -l 可直接查看手机id
idevicediagnostics 可让iPhone进行重启,关机,睡眠等。

我们可以利用libimobiledevice与ifuse进行shell封装,辅助实现自动化的测试过程。

另附上git地址:
https://github.com/libimobiledevice/libimobiledevice‎
https://github.com/libimobiledevice/ifuse

AFJSONRequestOperation不支持”text/html”问题

问题描述:输入法用AFJSONRequestOperation获取服务器更新消息。发现AFNetworking示例可以使用,换了服务器访问地址就不行了。

问题分析:打印出错误消息,如下:

Error Domain=AFNetworkingErrorDomain Code=-1016 "Expected content type {(
"text/json",
"application/json",
"text/javascript"
)}, got text/html"

看来是AFJSONRequestOperation只支持3种META,而服务器返回的是"text/html"。

问题解决:增加如下代码,让AFJSONRequestOperation支持"text/html"。

[AFJSONRequestOperationaddAcceptableContentTypes:[NSSetsetWithObjects:@"text/html", nil]];

UITableView的insert和delete操作与numberOfRowsInSection同步问题

问题描述:通过CrashRepoter得到如下报错信息:
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (0 inserted, 3 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

问题解决:在[self.tableView insertRowsAtIndexPaths:withRowAnimation:]和[tableView deleteRowsAtIndexPaths:withRowAnimation:]进行修改的操作前后加保护:
[tableView beginUpdates]和[self.tableView endUpdates]

Xcode升级导致插件失效

问题描述:Xcode升级后有些插件失效

问题分析:在控制台中查看log,显示是白名单问题

问题解决:把Xcode的UUID加入插件plist中:
XCODEUUID=`defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID`
defaults write ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/HOStringSense.xcplugin/Contents/Info DVTPlugInCompatibilityUUIDs -array-add $XCODEUUID

NSInvalidArgumentException’, reason: ‘Cannot create an NSPersistentStoreCoordinator with a nil model’

问题描述:NSInvalidArgumentException', reason: 'Cannot create an NSPersistentStoreCoordinator with a nil model'
问题解决:原因是缺少.momd文件,即缺少.xcdatamodeld文件,在工程中加上就行

SSH into iPhone over USB without Wi-Fi

最近在做iPhone守护进程,通过ssh和scp等脚本安装,速度总是不理想。同事告知如下可以通过usb运行ssh,找到如下好东西,附上安装运行方法。

1.准备python环境并下载usbmuxd
2.把手机通过USB连接Mac
3.运行python usbmuxd-1.0.8/python-client/tcprelay.py -t 22:2222
4.运行ssh root@localhost -p2222

这里有一篇for windows的:http://www.securitylearn.net/2012/10/11/ssh-into-iphone-over-usb-without-wi-fi/

CocoaPods错误

问题描述:用“pod update”更新,遇到如下错误

Pull is not possible because you have unmerged files.

Please, fix them up in the work tree, and then use 'git add/rm <file>'

as appropriate to mark resolution, or use 'git commit -a'.

问题解决

A bug was found in libgit2 and they had to execute a force push on the specs repo. This is what broke everyone's CocoaPods setup.

You can find the official post about this issue on the CocoaPods blog :http://blog.cocoapods.org/Repairing-Our-Broken-Specs-Repository/

The recommended way to fix your setup is to execute the following commands :

$ pod repo remove master
$ pod setup

If that doesn't work, you can also delete manually all your cached specs :

$ rm -rf ~/.cocoapods/
$ pod setup