rpetrich / libactivator

Centralized gestures and button management for iOS
http://rpetri.ch/cydia/activator/
181 stars 40 forks source link

libActiivator presentFromRootViewController #166

Closed iMokhles closed 10 years ago

iMokhles commented 10 years ago

Here is the code i used to create Activator Addon but it doesn't present the REComposeViewController

any suggest

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <libactivator/libactivator.h>
#import "REComposeViewController.h"

@interface WhatsAtor : NSObject<LAListener, UIAlertViewDelegate, REComposeViewControllerDelegate> {
@private
    REComposeViewController *av;
}
@end

@implementation WhatsAtor

- (BOOL)dismiss
{
    if (av)
    {
        [av release];
        av = nil;
        return YES;
    }
    return NO;
}

/*- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    [av release];
    av = nil;
}
*/
- (void)activator:(LAActivator *)activator receiveEvent:(LAEvent *)event
{
    if (![self dismiss])
    {
        av = [[REComposeViewController alloc] init];
        [av setTitle:@"WhatsAtor"];
        [av setHasAttachment:NO];
        [av setPlaceholderText:@"WhatsApp Message"];
        [av setDelegate:self];        

        [av presentFromRootViewController];

        [event setHandled:YES];
    }
}

- (void)activator:(LAActivator *)activator abortEvent:(LAEvent *)event
{
    // Called when event is escalated to higher event
    [self dismiss];
}

- (void)activator:(LAActivator *)activator otherListenerDidHandleEvent:(LAEvent *)event
{
    // Called when other listener receives an event
    [self dismiss];
}

- (void)activator:(LAActivator *)activator receiveDeactivateEvent:(LAEvent *)event
{
    // Called when the home button is pressed.
    // If showing UI, then dismiss it and call setHandled:.
    if ([self dismiss])
        [event setHandled:YES];
}

- (void)dealloc
{
    [av release];
    [super dealloc];
}

#pragma mark -
#pragma mark REComposeViewControllerDelegate

- (void)composeViewController:(REComposeViewController *)composeViewController didFinishWithResult:(REComposeResult)result
{
    [composeViewController dismissViewControllerAnimated:YES completion:nil];

    if (result == REComposeResultCancelled) {
        NSLog(@"Cancelled");
    }

    if (result == REComposeResultPosted) {

        NSString *inputText = [av text];
        NSString *url = [NSString stringWithFormat:@"whatsapp://send?text=%@", [inputText stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

        NSLog(@"Text: %@", av.text);
    }
}

+ (void)load
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    [[LAActivator sharedInstance] registerListener:[self new] forName:@"com.imokhles.WhatsAtor"];

    [pool release];
}

@end
rpetrich commented 10 years ago

I don't know what presentFromRootViewController does, but you generally shouldn't expect SpringBoard to have a root view controller (it doesn't). It's up to you to show your UI properly; Activator is only responsible for delivering the event.

iMokhles commented 10 years ago

This mean i should have a UIWindow or UIView ?

rpetrich commented 10 years ago

The most straightforward way is to create a UIWindow.

iMokhles commented 10 years ago

mmm okey i got it :+1: Thanks a lot