Skip to content

Instantly share code, notes, and snippets.

@robotconscience
Last active August 29, 2015 14:06
Show Gist options
  • Save robotconscience/5fe0afc5b5a7745c3052 to your computer and use it in GitHub Desktop.
Save robotconscience/5fe0afc5b5a7745c3052 to your computer and use it in GitHub Desktop.
openFrameworks iOS share window creation
//
// ofxiOSImageSharer.h
// Created by Brett Renfer on 9/9/14.
//
#pragma once
#import <UIKit/UIKit.h>
#include "ofMain.h"
@class ofxiOSViewController;
@interface ofxiOSInteractionController : NSObject<UIDocumentInteractionControllerDelegate>
@property (nonatomic, retain) ofxiOSViewController * viewController;
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller;
@end
class ofxiOSImageSharer
{
public:
void createShareWindow( string & url );
};
//
// ofxiOSImageSharer.mm
//
// Created by Brett Renfer on 9/9/14.
//
#include "ofxiOSImageSharer.h"
#import "ofxiOSViewController.h"
#import "ofxiOSExtras.h"
@interface ofxiOSInteractionController() <UIDocumentInteractionControllerDelegate> {
}
@end
@implementation ofxiOSInteractionController
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller {
return ofxiOSGetViewController();
}
@end
void ofxiOSImageSharer::createShareWindow(string & url)
{
@try {
ofLogWarning()<<"Creating delegate "<<url;
UIDocumentInteractionController * controller = [UIDocumentInteractionController interactionControllerWithURL:[NSURL URLWithString:[NSString stringWithUTF8String:url.c_str()]]];
ofxiOSInteractionController * delegate = [ofxiOSInteractionController alloc];
controller.delegate = delegate;
[controller presentOptionsMenuFromRect:CGRectZero inView:ofxiOSGetGLParentView() animated:YES];
}
@catch ( NSException *e ) {
NSLog(@"catching %@ reason %@", [e name], [e reason]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment