蝴蝶 0.3.15

Butterfly 0.3.15

测试已测试
语言语言 SwiftSwift
许可 MIT
发布上次发布2016年4月
SPM支持SPM

Wongzigii维护。



Butterfly 0.3.15

  • Wongzigii

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提供了一种优雅的方式,尽可能简单地向用户提供反馈。

快速查看

安装

通过CocoaPod

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项目目录下的文件导航器中。
  • 在Xcode中,通过点击右侧旁 Cultural tab中的蓝色项目图标,并选择"Targets"标题下的应用程序目标进行目标配置。
  • 在该窗口顶部的标签栏中,打开"Build Phases"面板。
  • 在"Target Dependencies"中添加Butterfly.framework。
  • 点击"Build Phases"面板左上角的+按钮,选择"New Copy Files Phase"。将新阶段重命名为"Copy Frameworks",将"Destination"设置为"Frameworks",并添加Butterfly.framework。

使用

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")
}

配置ButterflyFileUploader

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。

联系方式

Follow me on Twitter

许可证

Butterfly遵循MIT许可证,有关更多信息,请参阅许可证文件