GithubHelp home page GithubHelp logo

ekapujiw2002 / ios-picker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ink/ios-picker

0.0 2.0 0.0 60.84 MB

The easiest way to import content into your application. www.inkfilepicker.com

License: MIT License

ios-picker's Introduction

Ink Filepicker iOS Library

The easiest way to import content into your application. http://inkfilepicker.com

Note that Version 2.4.7 was the last version to support iOS6 and below. Please use that if you need are building for iOS6.

Dependencies

Usage Instructions

Importing

#import <FPPicker/FPPicker.h>

Opening Files

// To create the object
FPPickerController *fpController = [[FPPickerController alloc] init];

// Set the delegate
fpController.fpdelegate = self;

// Ask for specific data types. (Optional) Default is all files.
fpController.dataTypes = [NSArray arrayWithObjects:@"text/plain", nil];

// Select and order the sources (Optional) Default is all sources
fpController.sourceNames = [[NSArray alloc] initWithObjects: FPSourceImagesearch, FPSourceDropbox, nil];

// You can set some of the in built Camera properties as you would with UIImagePicker
fpController.allowsEditing = YES;

// Allowing multiple file selection
fpController.selectMultiple = YES;

// Limiting the maximum number of files that can be uploaded at one time.
fpController.maxFiles = 5;


/* Control if we should upload or download the files for you.
 * Default is yes. 
 * When a user selects a local file, we'll upload it and return a remote url
 * When a user selects a remote file, we'll download it and return the filedata to you.
 */
//fpController.shouldUpload = NO;
//fpController.shouldDownload = NO;

// Display it.
[self presentViewController:fpController animated:YES completion:nil];

Saving Files

// To create the object
FPSaveController *fpSave = [[FPSaveController alloc] init];

// Set the delegate
fpSave.fpdelegate = self;

// Ask for specific data mimetypes. (Optional) Default is all files.
fpController.dataTypes = [NSArray arrayWithObjects:@"text/plain", nil];

// Select and order the sources (Optional) Default is all sources
//fpSave.sourceNames = [NSArray arrayWithObjects: FPSourceCamera, FPSourceCameraRoll, FPSourceDropbox, FPSourceFacebook, FPSourceGmail, FPSourceBox, FPSourceGithub, FPSourceGoogleDrive, FPSourceImagesearch, nil];

// Set the data and data type to be saved.
fpSave.data = [[NSData *alloc] init] ;
fpSave.dataType = @"text/plain";   
//alternative: fpSave.dataExtension = @"txt"

//optional: propose the default file name
fpSave.proposedFilename = @"AwesomeFile";

// Display it.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
    UIPopoverController *popoverControllerA = [UIPopoverController alloc];    

    // You can set the delegate of the popover to be the FPPicker if you want FPPicker to report 
    // when the popover has been dismissed as a cancel
    popoverControllerA.delegate = fpSave;
    self.popoverController = [popoverControllerA initWithContentViewController:fpSave];
    popoverController.popoverContentSize = CGSizeMake(320, 520);
    [popoverController presentPopoverFromRect:[sender frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
    [self presentViewController:fpSave animated:YES completion:nil];
}

Delegate Functions

####FPPickerControllerDelegate

- (void)FPPickerController:(FPPickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;
  • Keys in the info dictionary
    • FPPickerControllerFilename
      • the NSString of the filename
      • e.g: 202342304.jpg
    • FPPickerControllerMediaType
      • the UTType of the file
      • e.g: public.image
    • FPPickerControllerMediaURL
      • The local location of the file.
      • e.g: assets-library://asset/asset.JPG?id=1000000001&ext=JPG
    • FPPickerControllerRemoteURL
    • (When Possible) FPPickerControllerOriginalImage
      • The UIImage
      • e.g: <UIImage: 0x8a37730>
    • (When Possible) FPPickerControllerKey
      • The S3 key if the developer has set up Amazon S3 account at Filepicker.io
        • e.g: JENAoTrDSPGFMrdxMd2R_photo.jpg
- (void)FPPickerController:(FPPickerController *)picker didPickMediaWithInfo:(NSDictionary *)info;
  • OPTIONAL (since version 2.4.6)
  • Keys in the info dictionary
    • (When Possible) FPPickerControllerThumbnailImage
    • The UIImage
    • e.g: <UIImage: 0x8a37730>
- (void)FPPickerControllerDidCancel:(FPPickerController *)picker
- (void)FPPickerController:(FPPickerController *)picker didFinishPickingMultipleMediaWithResults:(NSArray *)results;
  • OPTIONAL
  • Called when multiple select is enabled. Returns an Array of NSDictionary objects that have keys identical to those in didFinishPickingMediaWithInfo:
  • Note that the individual files will still trigger didPickMediaWithInfo, to allow you to start processing successful uploads in the background.

####FPSaveControllerDelegate Methods

- (void)FPSaveController:(FPSaveController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;

didFinishPickingMediaWithInfo happens when the save action has completed.

  • IMPORTANT NOTE: Info is an empty dictionary; nothing is being passed back
- (void)FPSaveControllerDidCancel:(FPSaveController *)picker;
  • Happens when the user cancels the save. If FPSaveController:didError is not implemented, it is also triggered when an error happens.
- (void)FPSaveControllerDidSave:(FPSaveController *)picker;
  • OPTIONAL (since version 2.4.6)
  • Didsave happens when the user chooses where to save.
- (void)FPSaveController:(FPSaveController *)picker didError:(NSDictionary *)info;
  • OPTIONAL (since version 2.4.6)
  • didError happens when an error happens.

####List of all sources:

  • Complete Listing
    • FPSourceCamera
      • The Local Camera
      • Open: "image/jpeg", "image/png"
      • Save: nil
    • FPSourceCameraRoll
      • The Local Photos
      • Open: "image/jpeg", "image/png", "video/quicktime"
      • Save: "image/jpeg", "image/png"
    • FPSourceDropbox
    • FPSourceFacebook
    • FPSourceGmail
    • FPSourceBox
    • FPSourceGithub
    • FPSourceGoogleDrive
      • drive.google.com
      • Open: "*/*"
      • Save: "*/*"
    • FPSourceImagesearch
      • Flickr Public Domain Image Search
      • Open: "image/jpeg"
      • Save: nil
    • FPSourceInstagram

Common tips

  1. The App builds, but crashes:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'No JSON parsing functionality available'
'NSInvalidArgumentException', reason: '-[UIImageView setImageWithURLRequest:placeholderImage:success:failure:]:

These are likely because JSONKit or AFNetworking are not linked. One fix for this is to add -all_load to Build Settings/Other Linker Flags. This will link the libraries that Filepicker needs.

  1. The app doesn't build: Duplicate symbol _AFURLEncodedStringFromStringWithEncoding or similar

You probabably are using AFNetworking. Since Filepicker depends on it, the compiler is adding AFNetworking twice and complaining. If you have a similar Duplicate symbol issue, it may be that you are using JSONkit or MBProgressHUD.

While this issue seems to be solved for XCode 4.4 Developer Preview 5 and beyond, the solution is to use the filepicker library without external libraries, then adding your own.

This issue was present for v1.0.0, but should be fixed from now on. Please report this to [email protected]
  1. The app builds, but crashes when I try to present the modal

It may be that you haven't set your apikey as it's checked the first time it's loaded.

  • Go to www.filepicker.io and register.
  • In your application's info.plist, add the following key/value:
Key: "Filepicker API Key"
Value: YOUR_API_KEY (that you got from registering)
  1. I'm using a popover in iPad and the login screens look terrible.

Our ability to deliver mobile pages is partly dependent on the service itself. Some have no mobile page at all. Others examine the user agent string and return the iPad version, not a popover friendly one. I've had good luck changing my user-agent string for a couple services.

Add this to your AppDelegate.m

/* 
 * This makese the login screens look much nicer on iPad
 */
+ (void)initialize {
    // Set user agent (the only problem is that we can't modify the User-Agent later in the program)
    NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3", @"UserAgent", nil];
    [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
}

Installation Instructions

For iOS Pros:

  1. Get an API Key

    • Go to Filepicker.io to register an account
    • Api Keys are typically randomized and 20 characters long.
  2. Insert the framework and bundle

    • Download or clone the repository.
    • Under /library, you'll find FPPicker.framework and FPPicker.bundle
    • Drag both into your project, typically in your framework folder
    • #import <FPPicker/FPPicker.h> in your viewController.h or other file where you want to use it.
  3. Settings

    • In your application's info.plist, add the following key/value:
Key: "Filepicker API Key"
Value: YOUR_API_KEY (that you got from step 1)
  1. Notes:

    • If this doesn't build, I've had luck adding -all_load -ObjC in Build_Settings/Other_Linker_Flags
    • You may need to add additional frameworks
      • AssetsLibrary.framework
      • QuartzCore.framework
      • CoreFoundation.framework
      • MobileCoreServices.framework
      • CoreGraphics.framework
      • Foundation.framework
      • UIKit.framework
  2. Use it

    • Initialize it:
FPPickerController *fpController = [[FPPickerController alloc] init];
fpController.fpdelegate = self;

//  - Delegate Methods:
- (void)FPPickerController:(FPPickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info;
- (void)FPPickerControllerDidCancel:(FPPickerController *)picker;

Running the Demo Project:

  1. Get an Api Key:

    • Go to Filepicker.io to register an account
    • Api Keys are typically randomized and 20 characters long.
  2. Insert the framework and bundle:

    • Download or clone the repository.
    • Open the /Examples/FPDemo.xcodeproj
  3. Settings:

    • In your application's info.plist, add the following key/value:
Key: "Filepicker API Key"
Value: YOUR_API_KEY (that you got from step 1)
  1. Build and Run

Starting from scratch:

  1. Get an Api Key:

    • Go to Filepicker.io to register an account
    • Api Keys are typically randomized and 20 characters long.
  2. Start a new Project

    • File/New/Project or Shift-Apple N
    • Single View Project
    - Name: FilepickerDemo - Device Family: iPad - Use Storyboards: False - Use Automatic Reference Counting: True
  3. Insert the framework and bundle

    • Download or clone the repository.
    - You can do this at the top of this git repository with either `ZIP` to get the zip or `git clone https://github.com/Filepicker/ios.git`. - Open up the folder. - Under `library/`, you'll find `FPPicker.framework` and `FPPicker.bundle` - Drag both into your project, typically in your framework folder - Choose to `Copy items into Destination Folder`
  4. Adding Additional Frameworks

    - Click on the .xcodeProj - Under `Build Phases -> Link Binary with Libraries`, add the following: - AssetsLibrary.framework - QuartzCore.framework - CoreGraphics.framework - MobileCoreServices.framework - Foundation.framework - CoreFoundation.framework - Under `Build Settings`, search for `Other Linker Flags` and set it to -all_load
  5. Write the code

    • You can copy and paste the following code into your ViewController.h and ViewController.m respectively.
    • In ViewController.h
      • We create a button, imageview, and a popover
    • In ViewController.m
      • We create an action when the button is pressed
      • We also have two delegates that respond when the Filepicker is finished.
    • ViewController.h Source
    • ViewController.m Source
  6. Build the User Interface

    • Drag a 'Image View' and a 'Rounded Rectangle Button' from the objects draw on the right.
    - Hook up the proper interfaces - On the right hand side, you'll notice three icons, one of which is the `File's Owner` - Hold down Ctrl, click and hold down the File Owner Orange Cube, then drag to the Image. A small popup will ask you to connect the file owner to the image. Choose `Outlet: Image`. - In a similar manner, ctrl drag from File Owner -> Button. Choose `Outlet: Button`. - Now, in the opposite direction, ctrl dragging from the button to the file owner. Choose `pickerAction:`. - Now if you right click on file owner, you should see the following.
  7. Add your API Key

    • Go to Supporting Files/FilepickerDemo-Info.plist. (Your's may vary if you didn't name it FilepickerDemo).
    • Right click, Add Row.
    • For the key: Filepicker API Key
    • For the value, paste in your apikey that you got from filepicker.io
  8. Run.

    • Click the run button in the upper right corner of xcode.
    • It should build and you can now choose a file!

ios-picker's People

Contributors

liyanchang avatar brettcvz avatar phlipper avatar

Watchers

James Cloos avatar Eka Puji Widiyanto 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.