React-native-onesignal: Is there an option to ignore the launchURL?

Created on 4 Nov 2016  ·  4Comments  ·  Source: OneSignal/react-native-onesignal

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.

All 4 comments

@jkasten2

@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.

No problem, thanks for the help @jkasten2!

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
Was this page helpful?
0 / 5 - 0 ratings