Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ilaunity · May 14, 2012 at 12:51 PM · pluginlocation

CLLocationManager didstartregionMonitoring not being called

I am creating a plugin for unity3d to use region monitoring. However the CllocationManager events are not not firing up. After searching a lot I read that this CLLocationManager needs to initialized in the main loop. However I am not sure how to do that when I am using the plugin.

Plugin code: RegionMonitoring.h

 #import <Foundation/Foundation.h>
 #import <CoreLocation/CoreLocation.h>
 
 @interface RegionMonitoringPlugin : NSObject <CLLocationManagerDelegate>
 {
     CLLocationManager *locationManager; 
 }
 
 -(void)enterRegionNotify;
 -(void)leaveRegionNotify;
 -(void)startMonitor:(float)latitude longitude:(float)longitude radius:(float)raduis;
 
 @end
  

RegionMonitoring.mm

 #import "RegionMonitoringPlugin.h"
 
 @implementation RegionMonitoringPlugin
 
 - (id) init
 {
     if (self = [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)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
 {
     NSLog (@"Started monitoring");
 }
 
 -(void)leaveRegionNotify
 {
     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
 { 
     [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];    
 }
 
 @end
 
 extern "C" {
         static RegionMonitoringPlugin *regionMonitor;
           // Unity callable function to start region monitoring
         BOOL _startRegionMonitoring(float m_latitude,float m_longitude, float m_radius)
         {
             if (![CLLocationManager regionMonitoringAvailable] || ![CLLocationManager regionMonitoringEnabled]){
                 NSLog (@"Region Monitoring not configured");
                 return NO;
             }
             
             if (regionMonitor == nil){
                 regionMonitor = [[RegionMonitoringPlugin alloc]  init] ;
             }
             [regionMonitor startMonitor:m_latitude longitude:m_longitude radius:m_radius];
             
             return YES;
         }
     
     void _showNotification (char *msg){
         if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Region Monitor Notification" message:[NSString stringWithUTF8String:(char *)msg] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
             [alertView show]; 
             [alertView release];
         }
     }
 }
         
         

Unity Code:

 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);
     
     [DllImport ("__Internal")]
     private static extern void _showNotification(string mes);
     
     public static void showNotification(string message){
         if (Application.platform != RuntimePlatform.OSXEditor)
             _showNotification(message);
     }
     
     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;
         
     }
 } 
      

Place where I am calling in unity:

 private void callFourSquare (string queryURL)
     {
         WWW www = new WWW(queryURL);
         StartCoroutine(WaitForRequest(www));    
     }
 
  IEnumerator WaitForRequest(WWW www)
     {
         yield return www;
         Debug.Log(WWW.UnEscapeURL (www.text));
         bool started =  RegionMonitoringMediator.startRegionMonitoring((28.023234f,77.232134F,10.0f);
         if (!started)
           Debug.LogError( "Could not start region monitoring");     }
             
            } 
             
             
         
         
         
         
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to pass accurate GPS location from android studio to unity? 0 Answers

iOS location permission plugin build fails 0 Answers

Unity Multiplayer RPC + iOS Game Center? 1 Answer

[SOLVED]Need help using a C++ bundle plugin in Unity3D using Xcode 2 Answers

How does Texture2D.CreateExternalTexture work? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges