llfbandit / app_links

Android App Links, Deep Links, iOs Universal Links and Custom URL schemes handler for Flutter.
https://pub.dev/packages/app_links
Apache License 2.0
221 stars 81 forks source link

wish to provide ios Objective-C custom AppDelegate sample code #115

Closed jackxuechen closed 7 months ago

jackxuechen commented 7 months ago

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!

jackxuechen commented 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'

import "AppDelegate.h"

import "GeneratedPluginRegistrant.h"

import <app_links/app_links-Swift.h>

@implementation AppDelegate

@end

jackxuechen commented 7 months ago

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];
}
llfbandit commented 7 months ago

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.