Skip to main content
Inspiring
April 17, 2012
Answered

How to open epub file in iBooks using ANE(iOS) ?

  • April 17, 2012
  • 1 reply
  • 4021 views

hello,

I tried to open epub file in iBooks using Native Extensions.

But, AIR app has crashed when calling ANE method (following: OpenEpub).

Have problems with how to access the epub file?

Or another problem?

MacOS:10.6.8

Xcode:4.2

FlashBulder:4.6

FlexSDK:4.6.0(default bundle version)

TestDevice:1st iPad (OS 5.0.1)

iOSNativeCode(this code works on native iOS app):

#import <UIKit/UIKit.h>

FREObject OpenEpub(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]){

    id delegate = [[UIApplication sharedApplication] delegate];

    UIWindow* window = [delegate window];

    UIButton* uiBtn = [[[UIButton alloc] init] retain];

    [window addSubview:uiBtn];

    NSString *fileToOpen = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"epub"];

    NSURL *url = [NSURL fileURLWithPath:fileToOpen];

    UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:url];

    [docController presentOpenInMenuFromRect:CGRectZero inView:uiBtn animated:true];

    [docController retain];

     const char *str = "Success";

     FREObject retStr;

     FRENewObjectFromUTF8(strlen(str)+1, (const uint8_t *)str, &retStr);

     return retStr;

}

ANE packaging directory:

ane/

     extension.xml

     key.p12

     platform/

          iOS/

               iOSNativeCode.a

               library.swf

               test.epub

extension.xml

<extension xmlns="http://ns.adobe.com/air/extension/3.1">

~~~~

Thanks!

This topic has been closed for replies.
Correct answer marumana

hi, i can open epub in iBooks using ANE !

    UIWindow *keyWindow= [[UIApplication sharedApplication] keyWindow];

    UIViewController *mainController = [keyWindow rootViewController];

    NSString *epubFileName= [[NSBundle mainBundle] pathForResource:@"test01" ofType:@"epub"];

    [epubFileName retain];

    NSURL *url = [NSURL fileURLWithPath:epubFileName];

    [url retain];

    UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:url];

    [docController retain];

    CGRect rectDocC = CGRectMake(800, 0, 0, 0);

    [docController presentOptionsMenuFromRect:rectDocC inView:mainController.view animated:YES];

thanks!

1 reply

marumanaAuthorCorrect answer
Inspiring
April 24, 2012

hi, i can open epub in iBooks using ANE !

    UIWindow *keyWindow= [[UIApplication sharedApplication] keyWindow];

    UIViewController *mainController = [keyWindow rootViewController];

    NSString *epubFileName= [[NSBundle mainBundle] pathForResource:@"test01" ofType:@"epub"];

    [epubFileName retain];

    NSURL *url = [NSURL fileURLWithPath:epubFileName];

    [url retain];

    UIDocumentInteractionController *docController = [UIDocumentInteractionController interactionControllerWithURL:url];

    [docController retain];

    CGRect rectDocC = CGRectMake(800, 0, 0, 0);

    [docController presentOptionsMenuFromRect:rectDocC inView:mainController.view animated:YES];

thanks!