Closed jackxuechen closed 7 months ago
I imported the <app_links/app_links-Swift.h>; Header files that use AppLinks.shared ask the following questions
/Runner/AppDelegate.m:28:20 Use of undeclared identifier 'AppLinks'
@implementation AppDelegate
(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions { [GeneratedPluginRegistrant registerWithRegistry:self];
// Retrieve the link from parameters NSURL *url = [AppLinks.shared getLinkWithLaunchOptions:launchOptions]; if (url != nil) { // We have a link, propagate it to your Flutter app [AppLinks.shared handleLinkWithURL:url]; return YES; // Returning true will stop the propagation to other packages }
return [super application:application didFinishLaunchingWithOptions:launchOptions]; }
@end
I've found a way 1.Create a Swift file that imports app_links and encapsulates the relevant methods
// AppLinksHelper.swift
import Foundation
import app_links
@objcMembers class AppLinksHelper: NSObject{
@objc static public func needHandleLink(launchOptions: [AnyHashable : Any]?) -> Bool{
if let url = AppLinks.shared.getLink(launchOptions: launchOptions) {
// We have a link, propagate it to your Flutter app
AppLinks.shared.handleLink(url: url)
return true // Returning true will stop the propagation to other packages
}
return false
}
}
2.In AppDelegate.m, import "Runner-Swift.h" and use the methods
// AppDelegate.m
#import "AppDelegate.h"
#import "GeneratedPluginRegistrant.h"
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import "Runner-Swift.h"
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
self.launchOptions = launchOptions;
BOOL isNeedHandle = [AppLinksHelper needHandleLinkWithLaunchOptions:launchOptions];
if(isNeedHandle){
return YES;
}
// Override point for customization after application launch.
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
Closing this since you found how to call this from objC langage. I don't know this langage, so I wouldn't have been of any help.
Is your feature request related to a problem? Please describe. wish to provide ios Objective-C custom AppDelegate sample code
Describe the solution you'd like I don't know much about ios development,wish to provide ios Objective-C custom AppDelegate sample code.
thank you!