Butterfly是一个轻量级库,它优雅地将崩溃报告和反馈功能与摇动事件集成在一起。
在iOS开发中,最大的问题之一是新功能和bug报告的反馈。
最常见的方法是使用mailto
发送一封枯燥无味的邮件
let str = "mailto:[email protected][email protected]&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20here!"
let url = NSURL(string: str)
UIApplication.sharedApplication().openURL(url)
Butterfly提供了一种优雅的方式,尽可能简单地向用户提供反馈。
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'Butterfly', '~> 0.3.13'
$ git submodule add https://github.com/wongzigii/Butterfly.git
Butterfly
文件夹,并将Butterfly.xcodeproj
拖动到您的app项目目录下的文件导航器中。import Butterfly
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
ButterflyManager.sharedManager.startListeningShake()
let uploader = ButterflyFileUploader.sharedUploader
uploader.setValue( "sample", forParameter: "folderName" )
uploader.setServerURLString("https://myserver.com/foo")
return true
}
ButterflyViewController
在发送按钮被按下时调用代理方法。您可能希望实现此方法以处理图片。然而,在Xcode版本6.4(6E35b)和Swift 2.0中,目前似乎没有方式来调用在协议中定义的静态(类)方法。考虑到这个问题,Butterfly在v0.3.13中包含ButterflyFileUploader
来处理上传任务。这个ButterflyFileUploader
类是在Alamofire的上传API封装。
func ButterflyViewControllerDidPressedSendButton(drawView: ButterflyDrawView?) {
if let image = imageWillUpload {
let data: UIImage = image
ButterflyFileUploader.sharedUploader.addFileData( UIImageJPEGRepresentation(data,0.8), withName: currentDate(), withMimeType: "image/jpeg" )
}
ButterflyFileUploader.sharedUploader.upload()
print("ButterflyViewController 's delegate method [-ButterflyViewControllerDidEndReporting] invoked\n")
}
ServerURLString
// @discussion Make sure your serverURLString is valid before a further application.
// Call `setServerURLString` to replace the default "http://myserver.com/uploadFile" with your own's.
public var serverURLString: String? = "http://myserver.com/uploadFile"
///
/// Set uploader 's server URL
///
/// @param URL The server URL.
///
public func setServerURLString( URL: String ) {
serverURLString = URL
}
///
/// Add one file or multiple files with file URL to uploader.
///
/// @param url The URL of the file whose content will be encoded into the multipart form data.
///
/// @param name The name to associate with the file content in the `Content-Disposition` HTTP header.
///
/// @param mimeType The MIME type to associate with the data in the `Content-Type` HTTP header.
///
public func addFileURL( url: NSURL, withName name: String, withMimeType mimeType: String? = nil ) {
files.append( ButterflyFileUploadInfo( name: name, withFileURL: url, withMimeType: mimeType ) )
}
///
/// Add one file or multiple files with NSData to uploader.
///
/// @param data The data to encode into the multipart form data.
///
/// @param name The name to associate with the file content in the `Content-Disposition` HTTP header.
///
/// @param mimeType The MIME type to associate with the data in the `Content-Type` HTTP header.
///
public func addFileData( data: NSData, withName name: String, withMimeType mimeType: String = "application/octet-stream" ) {
files.append( ButterflyFileUploadInfo( name: name, withData: data, withMimeType: mimeType ) )
}
有关更多信息,请查阅ButterflyFileUploader.swift。
Butterfly遵循MIT许可证,有关更多信息,请参阅许可证文件。