Code Monkey home page Code Monkey logo

butterfly's Introduction

Butterfly

Butterfly is a lightweight library for integrating bug-report and feedback features with shake-motion event.

Goals of this project

One of the main issues accross the iOS development is the feedback of new features and bug report.

The most common way is to use mailto to send a dry and boring email :

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 provides an elegant way to present users' feedback as easy as possible.

Quick Look

Installation

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod 'Butterfly', '~> 0.3.15'

Manually

$ git submodule add https://github.com/wongzigii/Butterfly.git
  • Open the Butterfly folder, and drag Butterfly.xcodeproj into the file navigator of your app project, under your app project.
  • In Xcode, navigate to the target configuration window by clicking on the blue project icon, and selecting the application target under the "Targets" heading in the sidebar.
  • In the tab bar at the top of that window, open the "Build Phases" panel.
  • Add Butterfly.framework within the "Target Dependencies"
  • Click on the + button at the top left of "Build Phases" panel and select "New Copy Files Phase". Rename this new phase to "Copy Frameworks", set the "Destination" to "Frameworks", and add Butterfly.framework.

Usage

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
}

Upload

ButterflyViewController protocol method invoked when send button pressed. You can conform this protocol to handle the image uploading. However, in Xcode Version 6.4 (6E35b) with Swift 2.0, there currently seems to be no way to call static (class) methods defined in a protocol (in pure Swift). Considering this issue, Butterfly included the ButterflyFileUploader to handle uploading stuff in v0.3.13. The ButterflyFileUploader class is an encapsulation under Alamofire 's upload 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")
}

Configuration of ButterflyFileUploader

// @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 ) )
}

For further information, please check out ButterflyFileUploader.swift.

Contact

Follow me on Twitter

License

Butterfly is under MIT LICENCE, see the LICENCE file for more info.

butterfly's People

Contributors

jason-idris avatar wongzigii avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.