Skip to content

Commit

Permalink
fix: ios
Browse files Browse the repository at this point in the history
暫時無定位權限
  • Loading branch information
lowrt committed Jun 29, 2024
1 parent 41c73bf commit 4e59bbf
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
12 changes: 12 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ PODS:
- Flutter
- flutter_local_notifications (0.0.1):
- Flutter
- geocoding_ios (1.0.5):
- Flutter
- geolocator_apple (1.2.0):
- Flutter
- GoogleDataTransport (9.4.1):
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30911.0, >= 2.30908.0)
Expand Down Expand Up @@ -92,6 +96,8 @@ DEPENDENCIES:
- Flutter (from `Flutter`)
- flutter_background_service_ios (from `.symlinks/plugins/flutter_background_service_ios/ios`)
- flutter_local_notifications (from `.symlinks/plugins/flutter_local_notifications/ios`)
- geocoding_ios (from `.symlinks/plugins/geocoding_ios/ios`)
- geolocator_apple (from `.symlinks/plugins/geolocator_apple/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`)
Expand Down Expand Up @@ -122,6 +128,10 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/flutter_background_service_ios/ios"
flutter_local_notifications:
:path: ".symlinks/plugins/flutter_local_notifications/ios"
geocoding_ios:
:path: ".symlinks/plugins/geocoding_ios/ios"
geolocator_apple:
:path: ".symlinks/plugins/geolocator_apple/ios"
package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios"
path_provider_foundation:
Expand All @@ -143,6 +153,8 @@ SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_background_service_ios: e30e0d3ee69e4cee66272d0c78eacd48c2e94aac
flutter_local_notifications: 4cde75091f6327eb8517fa068a0a5950212d2086
geocoding_ios: d7460f56e80e118d57678efe5c2cdc888739ff18
geolocator_apple: 6cbaf322953988e009e5ecb481f07efece75c450
GoogleDataTransport: 6c09b596d841063d76d4288cc2d2f42cc36e1e2a
GoogleUtilities: ea963c370a38a8069cc5f7ba4ca849a60b6d7d15
nanopb: 438bc412db1928dac798aa6fd75726007be04262
Expand Down
29 changes: 21 additions & 8 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import UIKit
import CoreLocation
import Flutter
import Firebase

class YourLocationManagerClass: NSObject, CLLocationManagerDelegate {
var locationManager: CLLocationManager?

func requestLocationPermission() {
locationManager = CLLocationManager()
}
}

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
var locationManager: YourLocationManagerClass?

override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
locationManager = YourLocationManagerClass()
locationManager?.requestLocationPermission()
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
8 changes: 7 additions & 1 deletion ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@
<string>$(FLUTTER_BUILD_NUMBER)</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>DPIP 將利用你的位置資訊,用以自動設定所在地並在地震發生時能較準確地預估所在地的最大震度。</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>DPIP 在開啟和後台執行時需要位置資訊,用以自動設定所在地並在地震發生時能較準確地預估所在地的最大震度。</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>DPIP 將利用你的位置資訊,用以自動設定所在地並在地震發生時能較準確地預估所在地的最大震度。</string>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>remote-notification</string>
<string>location</string>
<string>remote-notification</string>
</array>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import connectivity_plus
import firebase_core
import firebase_messaging
import flutter_local_notifications
import geolocator_apple
import package_info_plus
import path_provider_foundation
import shared_preferences_foundation
Expand All @@ -18,6 +19,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
FLTFirebaseMessagingPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseMessagingPlugin"))
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin"))
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
Expand Down

0 comments on commit 4e59bbf

Please sign in to comment.