Я пробую глубокие ссылки в Flutter, и в Android это работало идеально, как я хотел, но в iOS я пытаюсь слишком много дней, но не работаю, как я хотел
Я хочу, когда приложение открывается по ссылке, затем принес код ref и открываю экран входа в систему, а затем предварительно зафиксировал код Ref /Plesh -main.import 'package:vezigo/Models/app_imports.dart';
import 'package:app_links/app_links.dart';
String? initialReferralCode;
bool isLoggedIn = false;
@pragma('vm:entry-point')
Future _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
try {
await Firebase.initializeApp();
print("Handling a background message: ${message.messageId}");
} catch (e) {
print("Error handling background message: $e");
}
}
Future _firebaseMessagingAppOpenHandler(RemoteMessage message) async {
try {
await Firebase.initializeApp();
print("Handling a App open message: ${message.messageId}");
} catch (e) {
print("Error handling App open message: $e");
}
}
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
void initializeNotifications() async {
const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('');
final InitializationSettings initializationSettings =
InitializationSettings(android: initializationSettingsAndroid);
await flutterLocalNotificationsPlugin.initialize(initializationSettings);
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final prefs = await SharedPreferences.getInstance();
await prefs.setBool('apiCalledThisLaunch', false);
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
AnalyticsService().initialize();
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
FirebaseMessaging.onMessageOpenedApp.listen(_firebaseMessagingAppOpenHandler);
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print(
'Received a message while in the foreground: ${message.notification?.title}');
});
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
final accessToken = prefs.getString('accessToken');
final refreshToken = prefs.getString('refreshToken');
isLoggedIn = accessToken != null && refreshToken != null;
// Android deep link handling
try {
final appLinks = AppLinks();
final Uri? uri = await appLinks.getInitialLink();
if (uri != null && uri.path.contains('/referral/')) {
initialReferralCode = uri.pathSegments.last;
print("Android deep link referral code: $initialReferralCode");
}
} catch (e) {
print("Error reading Android deep link: $e");
}
// iOS deep link handling via MethodChannel
if (Platform.isIOS) {
const platform = MethodChannel('referral_channel');
try {
final String? code = await platform.invokeMethod('getReferralCode');
if (code != null && code.isNotEmpty) {
initialReferralCode = code;
print("Received referral code from iOS: $initialReferralCode");
}
} catch (e) {
print("Failed to get referral code from iOS: $e");
}
} else {
final appLinks = AppLinks();
final Uri? uri = await appLinks.getInitialLink();
if (uri != null && uri.path.contains('/referral/')) {
initialReferralCode = uri.pathSegments.last;
print("App opened with referral code: $initialReferralCode");
}
}
runApp(
MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => ProfileProvider()),
ChangeNotifierProvider(create: (context) => SignupProvider()),
ChangeNotifierProvider(create: (context) => Cart()),
ChangeNotifierProvider(create: (context) => AddressProvider()),
ChangeNotifierProvider(create: (context) => FavoriteProvider()),
],
child: const MyApp(),
),
);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
Widget initialScreen;
if (!isLoggedIn && initialReferralCode != null) {
initialScreen = LoginScreen(
referralCode: initialReferralCode!,
hideBackButton: true,
);
} else {
initialScreen = const SplashScreen();
}
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
brightness: Brightness.light,
),
darkTheme: ThemeData(
brightness: Brightness.light,
),
themeMode: ThemeMode.light,
home: initialScreen,
routes: {
'/cart': (context) => CartScreen(),
},
);
}
}
< /code>
info.pilist
CADisableMinimumFrameDurationOnPhone
ITSAppUsesNonExemptEncryption
CFBundleDevelopmentRegion
$(DEVELOPMENT_LANGUAGE)
CFBundleDisplayName
Sabjiking
CFBundleExecutable
$(EXECUTABLE_NAME)
CFBundleIdentifier
$(PRODUCT_BUNDLE_IDENTIFIER)
CFBundleInfoDictionaryVersion
6.0
CFBundleName
Sabjiking
CFBundlePackageType
APPL
CFBundleShortVersionString
1.0.12
CFBundleSignature
????
CFBundleVersion
24
GMSApiKey
AIzaSyDWEjhhgUXDO5wBE9fZoQxaOOl2MPXTF50
GMSPlacesApiKey
AIzaSyDWEjhhgUXDO5wBE9fZoQxaOOl2MPXTF50
INIntentsSupported
Intent
LSRequiresIPhoneOS
FirebaseAppDelegateProxyEnabled
UIBackgroundModes
fetch
remote-notification
NSAppTransportSecurity
NSAllowsArbitraryLoads
FirebaseMessagingAutoInitEnabled
FlutterDeepLinkingEnabled
NSCameraUsageDescription
This app requires access to the camera to take profile photos.
NSUserNotificationUsageDescription
We need notification access to provide updates.
NSLocationAlwaysUsageDescription
We need your location for background location updates.
NSLocationUsageDescription
We need your location to show it on the map.
NSLocationWhenInUseUsageDescription
We need your location to show nearby places on the map.
NSPhotoLibraryUsageDescription
This app requires access to the photo library to select profile photos.
UIApplicationSupportsIndirectInputEvents
UILaunchStoryboardName
LaunchScreen
UIMainStoryboardFile
Main
UISupportedInterfaceOrientations
UIInterfaceOrientationPortrait
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
UISupportedInterfaceOrientations~ipad
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
CFBundleURLTypes
CFBundleURLSchemes
com.arleven.vezigo
NSUserActivityTypes
NSUserActivityTypeBrowsingWeb
< /code>
Appdelegate.swift
import UIKit
import Flutter
import Firebase
import GoogleMaps
@main
@objc class AppDelegate: FlutterAppDelegate {
var initialReferralCode: String?
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
GMSServices.provideAPIKey("")
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
}
application.registerForRemoteNotifications()
GeneratedPluginRegistrant.register(with: self)
let controller = window?.rootViewController as! FlutterViewController
let channel = FlutterMethodChannel(name: "referral_channel", binaryMessenger: controller.binaryMessenger)
channel.setMethodCallHandler { call, result in
if call.method == "getReferralCode" {
result(self.initialReferralCode ?? "")
} else {
result(FlutterMethodNotImplemented)
}
}
// Handling deep links
if let url = launchOptions?[UIApplication.LaunchOptionsKey.url] as? URL {
handleDeepLink(url: url)
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
// Handle deep links (Universal Links)
override func application(_ application: UIApplication, continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let url = userActivity.webpageURL {
handleDeepLink(url: url)
}
return true
}
// Handle the deep link and extract referral code
private func handleDeepLink(url: URL) {
if let components = URLComponents(url: url, resolvingAgainstBaseURL: true),
let code = components.queryItems?.first(where: { $0.name == "code" })?.value {
initialReferralCode = code
print("Referral Code: \(code)")
}
}
override func application(
_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
) {
Messaging.messaging().apnsToken = deviceToken
super.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... lutter-ios
Flutter Deeplinks не работает в Flutter iOS ⇐ IOS
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
DeepLinks iOS не откроет мое приложение (как с типами URL, так и с связанными доменами)
Anonymous » » в форуме IOS - 0 Ответы
- 9 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Ошибка сборки Flutter iOS: «Двоичный файл не содержит» во время сборки flutter ios --release
Anonymous » » в форуме IOS - 0 Ответы
- 112 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Ошибка сборки Flutter iOS: «Двоичный файл не содержит» во время сборки flutter ios --release
Anonymous » » в форуме IOS - 0 Ответы
- 97 Просмотры
-
Последнее сообщение Anonymous
-