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

Is there an option to ignore the launchURL? #105

Closed
ccstorch opened this issue Nov 4, 2016 · 4 comments
Closed

Is there an option to ignore the launchURL? #105

ccstorch opened this issue Nov 4, 2016 · 4 comments

Comments

@ccstorch
Copy link

ccstorch commented Nov 4, 2016

Hello!

I already setup everything and the notifications are working perfectly.
When I send a normal message without url and press on the notification, the mobile app is launched, which is what I want.

But the one signal account that it is sending the notification is also used on a chrome extension, so there is an url for a website configured on the params of the notification. So when the mobile receive this notification, it is using the url for the website, and is opening a browser and not the mobile app.

Is there any way to ignore the url?
Or maybe stop the normal behavior and manually open the mobile app?
Or I am doing something wrong to get this result?

Thanks for the help.

@ccstorch ccstorch changed the title Is there an option to ignore launchURL? Is there an option to ignore the launchURL? Nov 4, 2016
@avishayil
Copy link
Contributor

@jkasten2

@jkasten2
Copy link
Member

jkasten2 commented Nov 8, 2016

@ccstorch @avishayil There isn't a way to disable the behavior for launch URL in the app. In your case you will need to send 2 separate notifications. One to just your Chrome extension with a launch URL set and another to your mobile app.

@ccstorch
Copy link
Author

ccstorch commented Nov 9, 2016

No problem, thanks for the help @jkasten2!

@ccstorch ccstorch closed this as completed Nov 9, 2016
@joshdholtz
Copy link

Swizzling the OneSignalHelper's displayWebView : method is a solution to also solve this problem. Its not a great approach but it does get the job done (for now).

⚠️ ONLY DO THIS IF YOU ARE FEELING YOLO ⚠️

#import <RCTOneSignal/RCTOneSignal.h>
#import <objc/runtime.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

	// Don't do this unless in dire yolo situations
	SwizzleClassMethod(NSClassFromString(@"OneSignalHelper"), @selector(displayWebView:), [AppDelegate class], @selector(displayWebView:));
	
	NSString *oneSignalAPIID = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"ONE_SIGNAL_API_ID"];
	self.oneSignal = [[RCTOneSignal alloc] initWithLaunchOptions:launchOptions appId:oneSignalAPIID];

	return YES;
}

+ (void) displayWebView:(NSURL*)url {
	NSLog(@"This is dumb");	
}

void SwizzleClassMethod(Class cOriginal, SEL orig, Class cNew, SEL new) {
	
	Method origMethod = class_getClassMethod(cOriginal, orig);
	Method newMethod = class_getClassMethod(cNew, new);
	
	cOriginal = object_getClass((id)cOriginal);
	cNew = object_getClass((id)cNew);
	
	if(class_addMethod(cOriginal, orig, method_getImplementation(newMethod), method_getTypeEncoding(newMethod))) {
		class_replaceMethod(cNew, new, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
	} else {
		method_exchangeImplementations(origMethod, newMethod);
	}
}

@end

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

4 participants