GithubHelp home page GithubHelp logo

irons163 / irsharemanager Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 58.02 MB

IRShareManager is a easy framework for deal with share files between the share extension and main app.

License: MIT License

Ruby 5.58% Objective-C 94.42%
shareextension share-extension ios objective-c files-management filelist

irsharemanager's Introduction

Build Status Platform

IRShareManager

  • IRShareManager is a easy framework for deal with share files between the share extension and main app.

Features

  • Easy to share files into main app by Share Extension.

Install

Git

  • Git clone this project.
  • Copy this project into your own project.
  • Add the .xcodeproj into you project and link it as embed framework.

Options

  • You can remove the demo and ScreenShots folder.

Cocoapods

  • Add pod 'IRShareManager' in the Podfile
target 'Demo' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for Demo
  pod 'IRShareManager'
end

target 'ShareExtension' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for ShareExtension
  pod 'IRShareManager'
end
  • pod install

Usage

Basic

Share Extension

  • Create Share Extension, go to Signing & Capabilities > + Capability > App Groups > Add a new group/group id

  • Put codes into ShareViewController.m

...
#import <IRShareManager/IRShare.h>

@implementation ShareViewController

- (BOOL)isContentValid {
    ...
    [IRShare sharedInstance].groupID = YOUR_GROUP_ID;
    return YES;
}

- (void)didSelectPost {
    [[IRShare sharedInstance] showSaveAlertIn:self];
    [[IRShare sharedInstance] didSelectPostWith:self.extensionContext];
}

@end

Load Resources

  • , go to Signing & Capabilities > + Capability > App Groups > Choose a group/group id that the same of yo

  • Load reseources which was shared by share extension in the main app

...
#import <IRShareManager/IRShare.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    ...
    [self saveImageIfExistInActionExtention];
    return YES;
}

- (void)applicationWillEnterForeground:(UIApplication *)application{
    NSLog(@"applicationWillEnterForeground");
    ...
    [self saveImageIfExistInActionExtention];
}

- (void)saveImageIfExistInActionExtention {
    [IRShare sharedInstance].groupID = YOUR_GROUP_ID;
    NSURL *directoryURL = [IRShare sharedInstance].directoryURL;
    
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray *keys = [NSArray arrayWithObject:NSURLIsDirectoryKey];
    NSDirectoryEnumerator *enumerator = [fileManager
    enumeratorAtURL:directoryURL
    includingPropertiesForKeys:keys
    options:0
    errorHandler:^(NSURL *url, NSError *error) {
        // Handle the error.
        // Return YES if the enumeration should continue after the error.
        return YES;
    }];
    
    NSMutableArray *urlsToDelete = [[NSMutableArray alloc] init];
    for (NSURL *url in enumerator) {
        NSLog(@"url:%@", url);
        NSError *error;
        NSNumber *isDirectory = nil;
        if (! [url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&error]) {
            // handle error
        }
        else if (! [isDirectory boolValue]) {
            [self saveImportFileIntoDB:url];
        }
        
        [urlsToDelete addObject:url];
    }
    
    for(NSURL *url in urlsToDelete){
        [[NSFileManager defaultManager] removeItemAtURL:url error:nil];
    }
}

- (void)saveImportFileIntoDB:(NSURL *)url {
    NSString *fileName = [[url absoluteString] lastPathComponent];
    fileName = [fileName stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSString *resourceDocPath = [[NSString alloc] initWithString:[[NSTemporaryDirectory() stringByDeletingLastPathComponent]stringByAppendingPathComponent:@"Documents"]];
    
    fileName = [self getNewFileNameIfExistsByFileName:fileName];
    
    NSString *filePath = [resourceDocPath stringByAppendingPathComponent:fileName];

    [[NSFileManager defaultManager] copyItemAtPath:[url path] toPath:filePath error:nil];
}

@end

Screenshots

Share Extension Files List
Share Extension Files List

irsharemanager's People

Contributors

irons163 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  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.