1

I have a subclass of GMSMarker called customMarker.

My user gets notifications every time he approaches one of the markers on the map.

I want that when the user clicks on a notification, the marker will be already selected (when the app opens from the notification) adn its infoWindow will be visible.

I try to do it like this:

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
    AroundersViewController *aroundersVC=[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"aroundersPage"];

    NSString *markerIdentifier=[[notification userInfo] objectForKey:@"markerIdentifier"];
    CustomMarker *notificationsMarker=[self.monitorLocationVC markerForIdentifier:markerIdentifier];

    [aroundersVC mapView:aroundersVC.mapView didTapMarker: notificationsMarker]; //App crashes here
}

But the app crashes with this error log message:

2016-02-11 20:39:30.355 App[15887:4216691] -[AroundersViewController mapView:didTapMarker:]: unrecognized selector sent to instance 0x7fa01bcf5890
2016-02-11 20:39:30.365 App[15887:4216691] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AroundersViewController mapView:didTapMarker:]: unrecognized selector sent to instance 0x7fa01bcf5890'
*** First throw call stack:
(
0   CoreFoundation                      0x0000000105257e65 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x0000000104cd0deb objc_exception_throw + 48
2   CoreFoundation                      0x000000010526048d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3   CoreFoundation                      0x00000001051ad727 ___forwarding___ + 487
4   CoreFoundation                      0x00000001051ad4b8 _CF_forwarding_prep_0 + 120
5   App                            0x0000000101988dab -[AppDelegate application:didReceiveLocalNotification:] + 523
6   UIKit                               0x000000010561cdc5 -[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:] + 3650
7   UIKit                               0x0000000105622cc1 __88-[UIApplication _handleApplicationLifecycleEventWithScene:transitionContext:completion:]_block_invoke + 214
8   UIKit                               0x0000000105622b95 -[UIApplication _handleApplicationLifecycleEventWithScene:transitionContext:completion:] + 508
9   UIKit                               0x0000000105602007 __70-[UIApplication scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 159
10  UIKit                               0x0000000105601c94 -[UIApplication scene:didUpdateWithDiff:transitionContext:completion:] + 843
11  FrontBoardServices                  0x0000000108027754 -[FBSSerialQueue _performNext] + 192
12  FrontBoardServices                  0x0000000108027ac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
13  CoreFoundation                      0x0000000105183a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
14  CoreFoundation                      0x000000010517995c __CFRunLoopDoSources0 + 556
15  CoreFoundation                      0x0000000105178e13 __CFRunLoopRun + 867
16  CoreFoundation                      0x0000000105178828 CFRunLoopRunSpecific + 488
17  GraphicsServices                    0x0000000107e53ad2 GSEventRunModal + 161
18  UIKit                               0x0000000105604610 UIApplicationMain + 171
19  App                            0x000000010199fd7f main + 111
20  libdyld.dylib                       0x0000000106c7f92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Does anybody have an idea?

Thanks!

FS.O
  • 403
  • 6
  • 24
  • what is custom marker? WHere did you declare it ? – Teja Nandamuri Feb 11 '16 at 18:56
  • didTapMArker expects marker of class type GMSMarker. Try to cast the class to GMSMarker type. – Teja Nandamuri Feb 11 '16 at 18:58
  • @Mr.T I've declared it in my VC. – FS.O Feb 11 '16 at 18:59
  • @Mr.T I've already tried: `GMSMarker *marker=notificationsMarker` and it's not solved the problem – FS.O Feb 11 '16 at 19:00
  • no you did it wrong. this [self.monitorLocationVC markerForIdentifier:markerIdentifier]; should return marker of type GMSMArker – Teja Nandamuri Feb 11 '16 at 19:02
  • try GMSMArker *marker=(GMSMarker *)[self.monitorLocationVC markerForIdentifier:markerIdentifier]; – Teja Nandamuri Feb 11 '16 at 19:03
  • @Mr.T Still the same – FS.O Feb 11 '16 at 19:04
  • could you please show the markerForIdentifier method ? – Teja Nandamuri Feb 11 '16 at 19:07
  • see the value returned by that method. – Teja Nandamuri Feb 11 '16 at 19:09
  • @Mr.T The value is correct (the correct marker) – FS.O Feb 11 '16 at 19:29
  • try if([notificationsMarker isKindOfClass:GMSMarker]){NSLOG(@"yes")} see if this loop gets executed or not before and after type cast – Teja Nandamuri Feb 11 '16 at 19:33
  • @Mr.T Both are being executed (with the cast and without it) – FS.O Feb 11 '16 at 19:37
  • @FS.O are you certain that the AroundersViewController implements mapView:didTapMarker:? – Josh Sklar Feb 18 '16 at 23:01
  • @JoshSklar That was the problem, thank you! But for some reason even when I call it the marker isn't being selected (the info window isn't visible), do you know why? – FS.O Feb 19 '16 at 05:51
  • @FS.O no problem! Glad you figured that out. Do you mean that even once you implement that method and call it, the marker isn't selected (the info window isn't visible)? – Josh Sklar Feb 19 '16 at 06:16
  • @JoshSklar Any idea? – FS.O Feb 21 '16 at 10:41
  • Possible duplicate of [mapView: didTapMarker isn't selecting a marker](http://stackoverflow.com/questions/35560480/mapview-didtapmarker-isnt-selecting-a-marker) - (that question is a follow-on from this one) – Saxon Druce Feb 23 '16 at 03:42
  • @FS.O it could possibly be related to the map view not being entirely created and set up by the time `mapView:didTapMarker:` is called. That view won't be rendered until it appears on screen, which will be after this method ends, and thus after `mapView:didTapMarker:` is called. I'd assume that the map view needs to be created/rendered before this method is called. You can try setting a property on that class (`AroundersViewController`), and calling `mapView:didTapMarker:` after the view loads and see if that changes anything. – Josh Sklar Feb 23 '16 at 05:35

0 Answers0