by Anonymous » 21 Mar 2025, 09:18
Ich recherchiere über die Erstellung von Bibliothek für React Native New Arch. Im Moment habe ich es mit dem Erstellen von Recreat-React-nativ-Bibliotheks < /code> zu tun, um eine LIC-Verfolgung von LIOs für eine bessere Anpassung zu erstellen. 0,48.3 < /li>
[*] React-nativ: 0.78.0 < /li>
< /ul>
Mein iOS-Projekt hat bereits: < /p>
- Hintergrund-Ort-Tracking Enable < /li>
findenCode: Select all
#import "generated/RNMyLocationTrackingSpec/RNMyLocationTrackingSpec.h"
@interface MyLocationTracking : NativeMyLocationTrackingSpecBase
@end
< /code>
MylocationTrack.mm
#import
#import "MyLocationTracking.h"
#import "MyLocationTracking-Swift.h"
@implementation MyLocationTracking
RCT_EXPORT_MODULE()
- (void)setInfo:(nonnull NSString *)baseURL token:(nonnull NSString *)token pushGPSInterval:(double)pushGPSInterval pushGPSDistance:(double)pushGPSDistance integrationId:(nonnull NSString *)integrationId {
MyLocationTrackingImpl *swiftInstance = [MyLocationTrackingImpl shared];
[swiftInstance setInfo:baseURL
rnToken:token
rnPushGPSInterval:pushGPSInterval
rnPushGPSDistance:pushGPSDistance
rnIntegrationId:integrationId
callback:^(NSDictionary *locationData) {
[self emitOnLocationChanged:locationData];
}];
}
- (nonnull NSNumber *)isProviderEnabled {
return @1;
}
- (nonnull NSNumber *)isServiceRunning {
return @1;
}
- (void)startWatchLocation {
[[MyLocationTrackingImpl shared] startWatchLocation];
}
- (void)stopWatchLocation {
[[MyLocationTrackingImpl shared] stopWatchLocation];
}
- (void)updateIntegrationId:(nonnull NSString *)integrationId {
[[MyLocationTrackingImpl shared] updateIntegrationId:integrationId];
}
- (std::shared_ptr)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared(params);
}
@end
< /code>
MylocationTrackingImpl.Swift: Dies funktioniert als Brücke, um die Kernstandortverfolgung mit dem objektiven C < /p>
zu verbindenimport Foundation
@objc
public class MyLocationTrackingImpl: NSObject {
private let myLocationTrackingCore = MyLocationTrackingCore()
// Singleton instance
@objc public static let shared = MyLocationTrackingImpl()
// Private initializer to enforce singleton
private override init() {
super.init()
print("=== MySingleton initialized! ===")
}
@objc public func setInfo(_ baseURL: String, rnToken token: String, rnPushGPSInterval pushGPSInterval: Double, rnPushGPSDistance pushGPSDistance: Double, rnIntegrationId integrationId: String, callback: @escaping ([String: Any]) -> Void) {
myLocationTrackingCore.setInfo(baseURL, rnToken: token, rnPushGPSInterval: pushGPSInterval, rnPushGPSDistance: pushGPSDistance, rnIntegrationId: integrationId, callback: callback)
}
@objc public func startWatchLocation() {
myLocationTrackingCore.startWatchLocation()
}
@objc public func stopWatchLocation() {
myLocationTrackingCore.stopWatchLocation()
}
@objc public func updateIntegrationId(_ integrationId: String) {
print("Updated Integration ID: \(integrationId)");
}
}
< /code>
MylocationTrackingCore.swift
import Foundation
import CoreLocation
class MyLocationTrackingCore: NSObject, CLLocationManagerDelegate {
var locationManager : CLLocationManager = CLLocationManager()
var BASE_URL : String = ""
var token : String = ""
var pushGPSInterval : Double = 10_000
var pushGPSDistance : Double = 0
var integrationId : String = "{}"
var pushGPSTimer: Date = Date()
var locationCallback: (([String: Any]) -> Void)?
func setInfo(_ baseURL: String, rnToken token: String, rnPushGPSInterval pushGPSInterval: Double, rnPushGPSDistance pushGPSDistance: Double, rnIntegrationId integrationId: String, callback: @escaping ([String: Any]) -> Void) {
print("= Initializing....");
self.BASE_URL = baseURL
self.token = token
self.integrationId = integrationId
// The minTime is in millisecond, here we need second
self.pushGPSInterval = (pushGPSInterval == 0 ? 10_000 : pushGPSInterval) / 1_000
self.pushGPSDistance = pushGPSDistance < 0 ? 0 : pushGPSDistance
// Callback
self.locationCallback = callback
print("Base url : \(self.BASE_URL)");
print("token : \(self.token)");
print("integrationId : \(self.integrationId)");
print("pushGPSInterval : \(self.pushGPSInterval)");
print("pushGPSDistance : \(self.pushGPSDistance)");
print("trigger callback :");
// Callback: try send data
if let locationCallback = self.locationCallback {
let newLocationData: [String: Any] = [
"lat": 37.7859,
"lng": -122.4364,
"alt": 15.0,
"spd": 6.0,
"course": 45.0
]
locationCallback(newLocationData)
print("- Location Callback triggered")
} else {
print("= Location Callback is nil")
}
// Init Location Manager
self.locationManager.delegate = self
self.locationManager.distanceFilter = self.pushGPSDistance
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.requestAlwaysAuthorization()
self.locationManager.allowsBackgroundLocationUpdates = true
self.locationManager.pausesLocationUpdatesAutomatically = false
self.locationManager.activityType = .automotiveNavigation
print("= Initialized");
}
func startWatchLocation() {
if CLLocationManager.locationServicesEnabled() {
self.pushGPSTimer = Date().addingTimeInterval(0)
self.locationManager.startUpdatingLocation()
print("Start location Location");
}
}
func stopWatchLocation() {
if CLLocationManager.locationServicesEnabled() {
self.locationManager.stopUpdatingLocation()
self.locationManager.delegate = nil
print("Stop location tracking")
}
}
func locationManager(
_ manager: CLLocationManager,
didUpdateLocations locations: [CLLocation]
) {
if let userLocation = locations.last {
let latitude = String(userLocation.coordinate.latitude)
let longitude = String(userLocation.coordinate.longitude)
let altitude = String(userLocation.altitude)
let speed = String(userLocation.speed)
let course = String(userLocation.course)
print("===============")
print("user latitude = \(latitude)")
print("user longitude = \(longitude)")
print("user altitude = \(altitude)")
print("user speed = \(speed)")
print("user course = \(course)")
} else {
print("===============")
print("No valid location data received")
}
}
func locationManager(
_ manager: CLLocationManager,
didFailWithError error: Error
) {
print("===============")
print("Error = \(error)")
}
}
< /code>
Im Moment kann die LIB: < /p>
Swifts Methode von Objective-C richtig aufrufen. MyLocationStrackingCore.Swift Execute, das Symbol ist weg
[/list]
Das [url=viewtopic.php?t=18916]Problem[/url] ist:
[list]
Func LOCOPS -LOCTELMANAGER: didupdatelocations
und didfailwitherror. />
Bitte lassen Sie mich wissen, ob Sie Ideen darüber haben, warum die didupdatelocations und didfailwitherror nicht ausgelöst werden.>
Ich recherchiere über die Erstellung von Bibliothek für React Native New Arch. Im Moment habe ich es mit dem Erstellen von Recreat-React-nativ-Bibliotheks < /code> zu tun, um eine LIC-Verfolgung von LIOs für eine bessere Anpassung zu erstellen. 0,48.3 < /li>
[*] React-nativ: 0.78.0 < /li>
< /ul>
Mein iOS-Projekt hat bereits: < /p>
[list]
Hintergrund-Ort-Tracking Enable < /li>
finden[code]#import "generated/RNMyLocationTrackingSpec/RNMyLocationTrackingSpec.h"
@interface MyLocationTracking : NativeMyLocationTrackingSpecBase
@end
< /code>
MylocationTrack.mm
#import
#import "MyLocationTracking.h"
#import "MyLocationTracking-Swift.h"
@implementation MyLocationTracking
RCT_EXPORT_MODULE()
- (void)setInfo:(nonnull NSString *)baseURL token:(nonnull NSString *)token pushGPSInterval:(double)pushGPSInterval pushGPSDistance:(double)pushGPSDistance integrationId:(nonnull NSString *)integrationId {
MyLocationTrackingImpl *swiftInstance = [MyLocationTrackingImpl shared];
[swiftInstance setInfo:baseURL
rnToken:token
rnPushGPSInterval:pushGPSInterval
rnPushGPSDistance:pushGPSDistance
rnIntegrationId:integrationId
callback:^(NSDictionary *locationData) {
[self emitOnLocationChanged:locationData];
}];
}
- (nonnull NSNumber *)isProviderEnabled {
return @1;
}
- (nonnull NSNumber *)isServiceRunning {
return @1;
}
- (void)startWatchLocation {
[[MyLocationTrackingImpl shared] startWatchLocation];
}
- (void)stopWatchLocation {
[[MyLocationTrackingImpl shared] stopWatchLocation];
}
- (void)updateIntegrationId:(nonnull NSString *)integrationId {
[[MyLocationTrackingImpl shared] updateIntegrationId:integrationId];
}
- (std::shared_ptr)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{
return std::make_shared(params);
}
@end
< /code>
MylocationTrackingImpl.Swift: Dies funktioniert als Brücke, um die Kernstandortverfolgung mit dem objektiven C < /p>
zu verbindenimport Foundation
@objc
public class MyLocationTrackingImpl: NSObject {
private let myLocationTrackingCore = MyLocationTrackingCore()
// Singleton instance
@objc public static let shared = MyLocationTrackingImpl()
// Private initializer to enforce singleton
private override init() {
super.init()
print("=== MySingleton initialized! ===")
}
@objc public func setInfo(_ baseURL: String, rnToken token: String, rnPushGPSInterval pushGPSInterval: Double, rnPushGPSDistance pushGPSDistance: Double, rnIntegrationId integrationId: String, callback: @escaping ([String: Any]) -> Void) {
myLocationTrackingCore.setInfo(baseURL, rnToken: token, rnPushGPSInterval: pushGPSInterval, rnPushGPSDistance: pushGPSDistance, rnIntegrationId: integrationId, callback: callback)
}
@objc public func startWatchLocation() {
myLocationTrackingCore.startWatchLocation()
}
@objc public func stopWatchLocation() {
myLocationTrackingCore.stopWatchLocation()
}
@objc public func updateIntegrationId(_ integrationId: String) {
print("Updated Integration ID: \(integrationId)");
}
}
< /code>
MylocationTrackingCore.swift
import Foundation
import CoreLocation
class MyLocationTrackingCore: NSObject, CLLocationManagerDelegate {
var locationManager : CLLocationManager = CLLocationManager()
var BASE_URL : String = ""
var token : String = ""
var pushGPSInterval : Double = 10_000
var pushGPSDistance : Double = 0
var integrationId : String = "{}"
var pushGPSTimer: Date = Date()
var locationCallback: (([String: Any]) -> Void)?
func setInfo(_ baseURL: String, rnToken token: String, rnPushGPSInterval pushGPSInterval: Double, rnPushGPSDistance pushGPSDistance: Double, rnIntegrationId integrationId: String, callback: @escaping ([String: Any]) -> Void) {
print("= Initializing....");
self.BASE_URL = baseURL
self.token = token
self.integrationId = integrationId
// The minTime is in millisecond, here we need second
self.pushGPSInterval = (pushGPSInterval == 0 ? 10_000 : pushGPSInterval) / 1_000
self.pushGPSDistance = pushGPSDistance < 0 ? 0 : pushGPSDistance
// Callback
self.locationCallback = callback
print("Base url : \(self.BASE_URL)");
print("token : \(self.token)");
print("integrationId : \(self.integrationId)");
print("pushGPSInterval : \(self.pushGPSInterval)");
print("pushGPSDistance : \(self.pushGPSDistance)");
print("trigger callback :");
// Callback: try send data
if let locationCallback = self.locationCallback {
let newLocationData: [String: Any] = [
"lat": 37.7859,
"lng": -122.4364,
"alt": 15.0,
"spd": 6.0,
"course": 45.0
]
locationCallback(newLocationData)
print("- Location Callback triggered")
} else {
print("= Location Callback is nil")
}
// Init Location Manager
self.locationManager.delegate = self
self.locationManager.distanceFilter = self.pushGPSDistance
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.requestAlwaysAuthorization()
self.locationManager.allowsBackgroundLocationUpdates = true
self.locationManager.pausesLocationUpdatesAutomatically = false
self.locationManager.activityType = .automotiveNavigation
print("= Initialized");
}
func startWatchLocation() {
if CLLocationManager.locationServicesEnabled() {
self.pushGPSTimer = Date().addingTimeInterval(0)
self.locationManager.startUpdatingLocation()
print("Start location Location");
}
}
func stopWatchLocation() {
if CLLocationManager.locationServicesEnabled() {
self.locationManager.stopUpdatingLocation()
self.locationManager.delegate = nil
print("Stop location tracking")
}
}
func locationManager(
_ manager: CLLocationManager,
didUpdateLocations locations: [CLLocation]
) {
if let userLocation = locations.last {
let latitude = String(userLocation.coordinate.latitude)
let longitude = String(userLocation.coordinate.longitude)
let altitude = String(userLocation.altitude)
let speed = String(userLocation.speed)
let course = String(userLocation.course)
print("===============")
print("user latitude = \(latitude)")
print("user longitude = \(longitude)")
print("user altitude = \(altitude)")
print("user speed = \(speed)")
print("user course = \(course)")
} else {
print("===============")
print("No valid location data received")
}
}
func locationManager(
_ manager: CLLocationManager,
didFailWithError error: Error
) {
print("===============")
print("Error = \(error)")
}
}
< /code>
Im Moment kann die LIB: < /p>
Swifts Methode von Objective-C richtig aufrufen. MyLocationStrackingCore.Swift Execute, das Symbol ist weg
[/list]
Das [url=viewtopic.php?t=18916]Problem[/url] ist:
[list]
Func LOCOPS -LOCTELMANAGER: didupdatelocations [/code] und didfailwitherror. /> [/list]
Bitte lassen Sie mich wissen, ob Sie Ideen darüber haben, warum die didupdatelocations und didfailwitherror nicht ausgelöst werden.>