Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to subscribe on application handleOpenURL out of appDelegate.m #14

Open
dukhanov opened this issue May 3, 2016 · 6 comments
Open

Comments

@dukhanov
Copy link

dukhanov commented May 3, 2016

Hello,
Will this work, in case I subscribe on event "handleOpenURL", outside of appDelegate.m?
For example, I can subscribe on event in cordova plugin:

FlicPlugin.m:

-(void)pluginInitialize
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:)name:@"flicApp" object:nil];
}
-(void)handleOpenURL:(NSNotification*)notification
{
   NSURL* url = [notification object];

   if ([url isKindOfClass:[NSURL class]]) {
        [[SCLFlicManager sharedManager] handleOpenUrl: url];
   }
}

I have done it, and:

  • I can grab flic button
  • But a flic button events does not happened

Have you tried to subscribe on event "handleOpenURL" outside of appDelegate.m?

@AntonMeier
Copy link
Contributor

I have actually never used Cordova so I am not sure how that works. First of all, I am not even sure wether or not AppDelegate events are also sent through the NSNotificationCenter, but I have never heard of it before at least.

The delegate callback that you will receive is application:openURL:sourceApplication:annotation: and that is sent to the AppDelegate.

I am sorry that I can't help you much, but I am sure that there must be a way to get the url when using Cordova. Add an NSLog() in the handleOpenURL to see if it is even called or not.

@dukhanov
Copy link
Author

dukhanov commented May 3, 2016

It is not depends on type of your application.
We can add this:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:)name:@"flicApp" object:nil];

for example into ViewController method:
https://github.com/50ButtonsEach/ios-boilerplate-objc/blob/master/ios-boilerplate-objc/ViewController.m#L30

Anyway, I saw, handleOpenURL was called:

myAppUrl://flicWasGrabbed?data=dc201f9e3d33ff1e2d249678dbe7650a5e91036b42f0ccbe48ff9d1360446615f270880f4ff4e2695f268fd6868aa47b287c92160082190f9657fa1f341153120102000000a4010000720100000000000000463031386358683502e9f1499819f963ce89d1e46c468a13b9341ad4d011a9691198bb6663f61741e44ebdfaca1a41d5d77d501ae8a68dd5de592fadd571153b4a92b5460ab967051fafb8680f1844f12b930b2e660305944ec903a5ad5336ea464446048a5d7ebbd8159e35905d42c8427d840534df29ed4bb296ec35d87b0afe134fa4ed524d81fd84291090d87311f76cbd3cb38b081337ac55bad196a5d84212f96a4f94e5e366181a76e45f115719d4c22368d294ea17e8b70bced545be7cda2b084510490cc413a44cec732d46d87b265cf309af147f6fc348a30948c7215469ff91d0ecc0db8bead7f6c4cbeeb2c91c6a130c543821e3a246d9a31136991408eb86a9744179f384d01ec8ca4a4726f90b922ef4395c80e4da717879&color=7EC250&userAssignedNamed=Greeny

But didReceiveButtonDown was not called, strange for me, this is why I asked about that.

@AntonMeier
Copy link
Contributor

AntonMeier commented May 3, 2016

Oh, well then it should be working. Did you receive the

- (void) flicManager:(SCLFlicManager * _Nonnull) manager didGrabFlicButton:(SCLFlicButton * _Nullable) button withError: (NSError * _Nullable) error;

callback? If so, did you also remember to set the delegate on the button (unless you have not already set the defaultButtonDelegate on the manager) ?

@dukhanov
Copy link
Author

dukhanov commented May 3, 2016

I received Could not grab message.

I set up defaultButtonDelegate on the manager.

In case I added into appDelegate, it works:

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options;
{
    BOOL wasHandled = NO;
    wasHandled = [[SCLFlicManager sharedManager] handleOpenURL:url];
    return wasHandled;
}

In case I removed application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options from appDelegate,
and add into viewController:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:)name:@"flicApp" object:nil];

It does not work.

This is fork from yours example project:
dukhanov/ios-boilerplate-objc@2d910dd

@AntonMeier
Copy link
Contributor

Very interesting.. I will take a look at this as soon as I have some spare time.

In the meantime, can do you think you can give me the error code that is sent in the didGrabButton callback. This way I might be able to see what the problem is without running your code.

@dukhanov
Copy link
Author

dukhanov commented May 3, 2016

I have checked it again, now it works...
It is really strange for me.

I will tune an iOS flic plugin https://github.com/dukhanov/Cordova-Flic for cordova and I will release it asap.

Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants