https://github.com/irons163/irsharemanager
IRShareManager is a easy framework for deal with share files between the share extension and main app.
https://github.com/irons163/irsharemanager
filelist files-management ios objective-c share-extension shareextension
Last synced: 8 months ago
JSON representation
IRShareManager is a easy framework for deal with share files between the share extension and main app.
- Host: GitHub
- URL: https://github.com/irons163/irsharemanager
- Owner: irons163
- License: mit
- Created: 2020-01-09T09:30:56.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-04-15T02:17:34.000Z (about 5 years ago)
- Last Synced: 2025-09-17T16:15:33.960Z (9 months ago)
- Topics: filelist, files-management, ios, objective-c, share-extension, shareextension
- Language: Objective-C
- Homepage:
- Size: 56.7 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README


# 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`
```objc
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
@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
```obj-c
...
#import
@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 |
|:---:|:---:|
|||