gpt4 book ai didi

iphone - 未调用 UIApplicationDelegate 方法

转载 作者:行者123 更新时间:2023-11-28 17:33:25 24 4
gpt4 key购买 nike

我正在尝试创建一个用于区域监控的插件。区域监控开始正常,但未调用函数 didfinishlaunching 和 didrecievelocalnotification。我不确定为什么会这样。

区域监控.h

 #import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>


@interface RegionMonitoringPlugin : NSObject <UIApplicationDelegate,CLLocationManagerDelegate>
{
CLLocationManager *locationManager;
}

-(void)enterRegionNotify;
-(void)leaveRegionNotify;
-(void)startMonitor:(float)latitude longitude:(float)longitude radius:(float)raduis;

@end

区域监控.mm

#import "RegionMonitoringPlugin.h"

@implementation RegionMonitoringPlugin

- (id) init
{
//if ( init == [super init]){
if (locationManager==nil){
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
}

return self;
}

-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
[self enterRegionNotify];
}

-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
[self leaveRegionNotify];
}

- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)regionwithError:(NSError *)error
{
NSLog(@"Location error %@, %@", error, @"Fill in the reason here");
}

-(void)leaveRegionNotify
{
NSLog(@"Starting region monitoring - check point 3");

UILocalNotification *note = [[UILocalNotification alloc] init];
note.alertBody= @"Region Left"; // ToAsk: What should be displayed
note.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:note];
[note release];

}


-(void)enterRegionNotify
{
UILocalNotification *note = [[UILocalNotification alloc] init];
note.alertBody= @"Region Left"; //ToAsk: what should be displayed ?
note.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:note];
[note release];

}

-(void)startMonitor:(float)latitude longitude:(float)longitude radius:(float)radius
{
NSLog(@"Starting region monitoring - check point 2");
[self leaveRegionNotify];
CLLocationCoordinate2D home;
home.latitude = latitude;
home.longitude = longitude;
CLRegion* region = [[CLRegion alloc] initCircularRegionWithCenter:home radius:radius identifier:@"region"];
[locationManager startMonitoringForRegion:region desiredAccuracy:kCLLocationAccuracyBest];
[region release];
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@"Starting region monitoring - checkpoint 4");

if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Region Monitor Notification" message:notification.alertBody delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
}


- (BOOL)application:(UIApplication *) application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(@"Test");
return TRUE;
}


@end


extern "C" {
static RegionMonitoringPlugin *regionMonitor;

// Unity callable function to start region monitoring
BOOL _startRegionMonitoring(float m_latitude,float m_longitude, float m_radius)
{

NSLog(@"Starting region monitoring");
if (![CLLocationManager regionMonitoringAvailable] || ![CLLocationManager regionMonitoringEnabled] )
return NO;

if (regionMonitor == nil){
regionMonitor = [[RegionMonitoringPlugin alloc] init] ;
}
[regionMonitor startMonitor:m_latitude longitude:m_longitude radius:m_radius];
return YES;

}
}

插件的统一代码:RegionMonitorMediater.h

using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;

public class RegionMonitoringMediator {

/*Interface to native implementation */
[DllImport ("__Internal")]
private static extern bool _startRegionMonitoring (float m_latitude,float m_longitude, float m_radius);

public static bool startRegionMonitoring (float latitude,float longitude, float radius)
{
/*Call plugin only when running on real device*/
if (Application.platform != RuntimePlatform.OSXEditor)
return _startRegionMonitoring ( latitude , longitude , radius);
else return false;

}
}

调用区域监听

我做的OnPress事件

bool startedRM = RegionMonitoringMediator.startRegionMonitoring(77.0f,28.0f,10.0f);

最佳答案

每个应用程序只允许一个 UIApplicationDelegate。当 Unity3D 为 iPhone 播放器构建您的应用程序时,将生成一个类 AppController 作为接口(interface)。

此类是插入代码以调用 RegionMonitoringPlugin 的地方。

关于iphone - 未调用 UIApplicationDelegate 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10561655/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com