मेरी कोड के सभी AppDelegate.m में है:महत्वपूर्ण परिवर्तन स्थान प्रतिनिधि तरीकों नहीं बुलाया जा रहा है
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
_locationMgr = [[CLLocationManager alloc] init];
[_locationMgr setDelegate:self];
if([_locationMgr respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)])
[_locationMgr setAllowsBackgroundLocationUpdates:YES];
CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus];
if([launchOptions valueForKey:UIApplicationLaunchOptionsLocationKey] != nil) {
NSLog(@"relaunching because of significant location change - restarting SLC");
[_locationMgr startMonitoringSignificantLocationChanges];
}
else
{
if (authorizationStatus == kCLAuthorizationStatusAuthorizedAlways) {
NSLog(@"launching with authorization to always use location - starting SLC");
[_locationMgr startMonitoringSignificantLocationChanges];
}
else
{
NSLog(@"launching with no authorization to always use location - requesting authorization");
if([_locationMgr respondsToSelector:@selector(requestAlwaysAuthorization)])
[_locationMgr requestAlwaysAuthorization];
}
}
if([userdefaults objectForKey:@"pfuser"] == nil) {
NSLog(@"in delegate signup");
SignUpController *signup = [[SignUpController alloc] init];
[self.window setRootViewController:signup];
}
else {
ViewController *map = [[ViewController alloc] init];
[self.window setRootViewController:map];
}
[self.window makeKeyAndVisible];
return YES;
}
- (void)startSignificantChangeUpdates
{
deviceNotFoundAlertController = [UIAlertController alertControllerWithTitle:@"START" message:@"startSignificantChangeUpdates called" preferredStyle:UIAlertControllerStyleAlert];
[deviceNotFoundAlertController addAction:deviceNotFoundAlert];
// Create the location manager if this object does not
// already have one.
if (nil == _locationMgr) {
_locationMgr = [[CLLocationManager alloc] init];
_locationMgr.delegate = self;
}
[CLLocationManager significantLocationChangeMonitoringAvailable];
[_locationMgr startMonitoringSignificantLocationChanges];
}
-(void)locationManger:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"didFailWithError: %@", error);
deviceNotFoundAlertController = [UIAlertController alertControllerWithTitle:@"LOCATION FAIL" message:@"didFailWithError" preferredStyle:UIAlertControllerStyleAlert];
[deviceNotFoundAlertController addAction:deviceNotFoundAlert];
}
// Delegate method from the CLLocationManagerDelegate protocol.
- (void)_locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
deviceNotFoundAlertController = [UIAlertController alertControllerWithTitle:@"LOCATION UPDATE" message:@"didUpdateLocations called" preferredStyle:UIAlertControllerStyleAlert];
[deviceNotFoundAlertController addAction:deviceNotFoundAlert];
// If it's a relatively recent event, turn off updates to save power.
CLLocation* location = [locations lastObject];
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (fabs(howRecent) < 15.0) {
// If the event is recent, do something with it.
NSLog(@"latitude %+.6f, longitude %+.6f\n",
location.coordinate.latitude,
location.coordinate.longitude);
}
}
अलर्ट में से कोई भी हो, ऐसा प्रतिनिधि पद्धतियों को बुलाया नहीं किया जा रहा है लगता है।
अद्यतन
अब मेरे पास है:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
deviceNotFoundAlert = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
...
}
// Delegate method from the CLLocationManagerDelegate protocol.
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
deviceNotFoundAlertController = [UIAlertController alertControllerWithTitle:@"LOCATION UPDATE" message:@"didUpdateLocations called" preferredStyle:UIAlertControllerStyleAlert];
[deviceNotFoundAlertController addAction:deviceNotFoundAlert];
// If it's a relatively recent event, turn off updates to save power.
CLLocation* location = [locations lastObject];
NSDate* eventDate = location.timestamp;
NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
if (fabs(howRecent) < 15.0) {
// If the event is recent, do something with it.
NSLog(@"latitude %+.6f, longitude %+.6f\n",
location.coordinate.latitude,
location.coordinate.longitude);
}
}
जब मैं ऐप का परीक्षण, मैं इसे अपने घर में खोलें, और फिर इसे बंद, इतना है कि यह भेजना चाहिए जब मैं अपने घर छोड़ने किसी बिंदु पर एक चेतावनी (या 3), लेकिन मुझे किसी भी प्रतिनिधि तरीकों से अलर्ट नहीं मिल रहे हैं (जहां मैंने अलर्ट लगाए थे)।
मैं सिर्फ एक विचार था, शायद मैं मुख्य UIViewController
, नहीं AppDelegate
से अलर्ट प्रदर्शित करने के लिए है?
यही कारण है कि मैं अलर्ट नहीं दिखाई दे रहा हो सकता है: How do I add a UIAlertController in app delegate (obj-c)
अद्यतन
यह कैसे मैं अब अलर्ट कर रहा हूँ है:
deviceNotFoundAlertController = [UIAlertController alertControllerWithTitle:@"START" message:@"startSignificantChangeUpdates called" preferredStyle:UIAlertControllerStyleAlert];
[deviceNotFoundAlertController addAction:deviceNotFoundAlert];
alertWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
alertWindow.rootViewController = [[UIViewController alloc] init];
alertWindow.windowLevel = UIWindowLevelAlert + 1;
[alertWindow makeKeyAndVisible];
[alertWindow.rootViewController presentViewController:deviceNotFoundAlertController animated:YES completion:nil];
अद्यतन
अलर्ट समस्या नहीं प्रतीत होती, एले startSignificantChangeUpdates
में आरटी कभी प्रकट नहीं होता है। एक बार जब मैं अपने शुरुआती स्थान से 500 मीटर हूं तो क्या यह दिखाना चाहिए?
अद्यतन
किसी को भी मुझे इस को समझने में मदद कर सकते हैं?
आपके प्रतिनिधि वस्तु के तरीकों को उस थ्रेड से बुलाया जाता है जिसमें आपने संबंधित स्थान सेवाएं शुरू की थीं। उस थ्रेड के पास एक सक्रिय रन लूप होना चाहिए, जैसा कि आपके एप्लिकेशन के मुख्य थ्रेड में पाया गया है।
अद्यतन
मुझे लगता है कि मैं पता लगा क्या उपर्युक्त उद्धरण कह रहा है ... और मैं अब इस राशि - मैं कल का परीक्षण होगा।
...
if([launchOptions valueForKey:UIApplicationLaunchOptionsLocationKey] != nil) {
NSLog(@"relaunching because of significant location change - restarting SLC");
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[_locationMgr startMonitoringSignificantLocationChanges];
});
}
else
{
if (authorizationStatus == kCLAuthorizationStatusAuthorizedAlways) {
NSLog(@"launching with authorization to always use location - starting SLC");
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[_locationMgr startMonitoringSignificantLocationChanges];
});
}
else
{
NSLog(@"launching with no authorization to always use location - requesting authorization");
if([_locationMgr respondsToSelector:@selector(requestAlwaysAuthorization)])
[_locationMgr requestAlwaysAuthorization];
}
}
...
मुझे लगता है कि कोड अपने स्वयं के धागे पर स्थान सेवाएं शुरू कर रहा है। एक बात मैंने पहले ही देखी है, यह है कि जब मैं ऐप से बाहर निकलता हूं, तो शीर्ष दाएं स्थान का स्थान दूर हो जाता है। मैंने अभी आईओएस 10 में अपडेट किया है। आईओएस 9 में शीर्ष दाएं स्थान में स्थान तीर वहां रहेगा, लेकिन जब ऐप नहीं चल रहा था तो यह केवल एक काला रूपरेखा होगी। यह सिर्फ कुछ ऐसा हो सकता है जो उन्होंने आईओएस 10 के साथ बदल दिया, या अब क्योंकि मैंने 10 तक अपडेट किया है, अब कुछ और काम नहीं कर रहा है। या ऐसा तब होता है जब स्थान सेवाएं अपने स्वयं के धागे पर चलती हैं।यहाँ से: iOS start Background Thread
अद्यतन
शायद मैं धागा सही ढंग से उपयोग नहीं कर रहा है, लेकिन जैसा कि मैंने कहा, अब जब मैं अनुप्रयोग बंद करें, स्थान सेवाओं इस्तीफा। जब मैं धागे के बिना ऐसा कर रहा था तो स्थान सेवा तीर एक रूपरेखा के रूप में, शीर्ष दाएं में रहेगा।
अद्यतन
मैंने पढ़ा है कि सेवा मुख्य थ्रेड पर शुरू किया जाना चाहिए - तो अब मेरे पास है:
CLAuthorizationStatus authorizationStatus= [CLLocationManager authorizationStatus];
NSLog(@"launching with no authorization to always use location - requesting authorization");
if([_locationMgr respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[_locationMgr requestAlwaysAuthorization];
}
if([launchOptions valueForKey:UIApplicationLaunchOptionsLocationKey] != nil) {
NSLog(@"relaunching because of significant location change - restarting SLC");
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[_locationMgr startMonitoringSignificantLocationChanges];
});
}
else if (authorizationStatus == kCLAuthorizationStatusAuthorizedAlways) {
NSLog(@"launching with authorization to always use location - starting SLC");
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[_locationMgr startMonitoringSignificantLocationChanges];
});
}
else {
//
}
सही दिखाई नहीं देता जब अनुप्रयोग है में तीर बंद, क्या यह आईओएस 10 के लिए कुछ नया है जहां वे इसे और नहीं दिखाते हैं?
अद्यतन
मैंने गलती से नष्ट कर दिया: _locationMgr = [[CLLocationManager alloc] init];
मैं में डाल दिया और अब तीर हमेशा वहाँ है, आज का परीक्षण करने जा रहा है।
अद्यतन
मैं इसे कोई अलर्ट परीक्षण किया है, अभी भी।
क्या आपने प्लेस्ट में स्थान सेवा का उपयोग करने के लिए कॉन्फ़िगर किया था ?? यदि नहीं तो आपको इसे करने की ज़रूरत है।दो विकल्प अनुरोध हैं हमेशा प्राधिकरण और अनुरोध WhenInUseAuthorization। मुझे बताएं कि क्या यह आपकी समस्या हल करता है – Janmenjaya
हाय, हाँ मेरे पास है - जब मैं इसे टाइप करता हूं तो 'गोपनीयता - स्थान हमेशा उपयोग विवरण' में बदल जाता है और मैंने दूसरे कॉलम में एक संदेश दिया ... वास्तव में कुछ अलग है ... मुझे लगता है कि मुझे दोबारा परीक्षण करने की ज़रूरत है बीमार आपको – ewizard
पता है कि मेरे पास 'आइटम 0' के साथ 'आवश्यक पृष्ठभूमि मोड' और 'स्थान अपडेट के लिए ऐप रजिस्ट्रार' – ewizard