你好!
我已经设置了所有内容,并且通知运行良好。
当我发送一条没有 url 的普通消息并按下通知时,移动应用程序就会启动,这就是我想要的。
但是它发送通知的一个信号帐户也用于 chrome 扩展,因此在通知的参数上配置了一个网站的 url。 因此,当手机收到此通知时,它使用的是网站的 url,并且正在打开浏览器而不是移动应用程序。
有什么办法可以忽略网址吗?
或者也许停止正常行为并手动打开移动应用程序?
或者我做错了什么来得到这个结果?
谢谢您的帮助。
@jkasten2
@ccstorch @avishayil没有办法在应用程序中禁用启动 URL 的行为。 在您的情况下,您将需要发送 2 个单独的通知。 一个是您的带有启动 URL 集的 Chrome 扩展程序,另一个是您的移动应用程序。
没问题,感谢@jkasten2 的帮助!
Swizzling OneSignalHelper
的displayWebView :
方法也是解决此问题的一种解决方案。 它不是一个很好的方法,但它确实完成了工作(目前)。
⚠️ 仅当您感觉 YOLO 时才这样做⚠️
#import <RCTOneSignal/RCTOneSignal.h>
#import <objc/runtime.h>
<strong i="9">@implementation</strong> 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);
}
}
<strong i="10">@end</strong>