Hi,
What is wrong with the PerformSelector code?
[Export("voidendbgtask:")]
void stopAndResetBgTaskIfNeeded()
{
LogToScreen();
if (isManagerRunning)
{
stopBackgroundTask();
}
else
{
stopBackgroundTask();
startBackgroundTask();
}
}
private void checkLocationTimerEvent()
{
LogToScreen();
stopCheckLocationTimer();
startLocationManager();
Selector s = new Selector("voidendbgtask:");
UIApplication.SharedApplication.PerformSelector(s, null, 5.0);
}
When I do this I get an error: Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[UIApplication voidendbgtask:]: unrecognized selector sent to instance 0x14da2a90
I see two issues:
1) no need for a semi-colon in the selector name since your method does not have any parameters.
2) Make sure 'stopAndResetBgTaskIfNeeded' is defined in a class that derives from NSObject and replace UIApplication.SharedApplication.PerformSelector(s, null, 5.0); to PerformSelector(s, null, 5.0);
Answers
I see two issues:
1) no need for a semi-colon in the selector name since your method does not have any parameters.
2) Make sure 'stopAndResetBgTaskIfNeeded' is defined in a class that derives from NSObject and replace UIApplication.SharedApplication.PerformSelector(s, null, 5.0); to PerformSelector(s, null, 5.0);
Thanks. Problem solved!!