![](/img/trans.png)
[英]How to receive data on click of notification in ios, when app is killed ,( react-native-fcm module to get push notification in IOS)
[英]Perform action after push notification when app is killed : react-native, IOS
在IOS反應本地項目上工作。
當應用程序為DEAD並收到推送通知時-
我希望應用程序根據通知的有效負載導航到另一個頁面。 當應用程序處於前台或后台時-一切正常。 當該應用被殺死時-該應用會自動打開。
下面添加的是我的Appdelegate.m代碼。 我正在捕獲通知並將其記錄到控制台,但是我不知道如何將其發送給本地響應。
使用RN 0.46
expo 19(已與ExpoKit分離)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_window.backgroundColor = [UIColor whiteColor];
[[ExpoKit sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
_rootViewController = [ExpoKit sharedInstance].rootViewController;
_window.rootViewController = _rootViewController;
[_rootViewController loadReactApplication];
[_window makeKeyAndVisible];
if ([launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (notification) {
//logs the notification's payload
NSLog(@"app recieved notification from remote%@",notification);
} else {
NSLog(@"app did not recieve notification");
}
}
return YES;
}
要實現這種行為,您需要為您的應用實現某種深度鏈接 。 這樣,您可以在本機應用程序中偵聽有效負載並導航至正確的屏幕。 react-navigation和react-native-navigation具有用於深度鏈接的自己的實現。
從本機文檔中,
處理深層鏈接
如果您的應用是從注冊到應用的外部網址啟動的,則可以從任何需要的組件訪問和處理它
componentDidMount() {
Linking.getInitialURL().then((url) => {
if (url) {
console.log('Initial url is: ' + url);
}
}).catch(err => console.error('An error occurred', err));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.