App State Preservation and Restoration in MonoTouch - ios

I need to implement the status preservation protocol in my monotouch app, like described in the Apple Docs:
App State Preservation and Restoration
But I cannot find any documentation or project sample on the Xamarin website about the UIViewControllerRestoration Protocol.
Any help is appreciated.

This protocol is not currently bound in MonoTouch. There is a bug for it here:
https://bugzilla.xamarin.com/show_bug.cgi?id=8778
That said, there is a similar callback in the AppDelegate, application:viewControllerWithRestorationIdentifierPath:coder: that is bound in MonoTouch to the method:
UIViewController GetViewController (UIApplication application, string[] restorationIdentifierComponents, NSCoder coder).
This will be called once for each saved controller that has no restoration class set. Therefore, in lieu of the restoration class, you could override this method in the App Delegate.

Related

Tell background state of action extension

UIApplication has the handy applicationState property that allows you to see if your application is in the background or not. In action (and share) extensions, use of UIApplication is illegal, and even if you do get an instance of it within an extension it always reports applicationState=UIApplicationStateBackground. I also tried observing UIApplicationDidEnterBackgroundNotification, it never fires.
Is there a way to effectively tell if an extension is running within an app that's in the foreground or background?
Post iOS 8.2, You can observe the notifications listed here.
NSExtensionHostDidBecomeActiveNotification
NSExtensionHostWillResignActiveNotification
NSExtensionHostDidEnterBackgroundNotification
NSExtensionHostWillEnterForegroundNotification
Be sure to check that you are on a device of the appropriate version before signing up for these notifications, or your extension will crash, as they will be nil.

Xamarin MvvmCross iOS state restoration issues

I am currently unable to get state save/restore working for an iOS (target iOS 8) Xamarin solution using MvvmCross. The core view model implements save/restore as specified here https://github.com/MvvmCross/MvvmCross/wiki/View-Model-Lifecycle
The state is saved and restored correctly in the Android version of the solution, but is not working for the iOS version.
I have set a Restoration ID on the associated view controllers, and added the “opt in” methods to the app delegate class…
public override bool ShouldSaveApplicationState(UIApplication application, NSCoder coder)
{
return true;
}
public override bool ShouldRestoreApplicationState(UIApplication application, NSCoder coder)
{
return true;
}
If I create a basic single view iOS Xamarin app then I do see a call to the view controller’s EncodeRestorableState override method when the app goes into the background. However, for a similar simple MvvmCross implementation, this overridden method is no longer called (and neither is the SaveState method of the view model).
I have been unable to find anything to help, and only seem to find many people asking similar questions, but currently with no answers (e.g. SaveState in MvvmCross is not being called in an iOS application).
I would be very grateful for any information that could help point me in the right direction with this. Thanks.

Explanation of AppDelegate? [duplicate]

This question already has answers here:
What is the AppDelegate for and how do I know when to use it?
(4 answers)
Closed 8 years ago.
I have an android background . I want to learn XCode . Now i want to understand what does the Appdelegate.h and Appdelegate.m do? As in Android Manifest.xml is the mainFile which launches other Activities . permissions, feature ,broadcast service etc are written in it.
Now can some one explain me the importance of AppDelegate file and explain its component and benefits ?
And where to include permission or Service or BroadCast in app.
I have created an app in Android . Now i am creating it in IPhone which requires permission and services...
Thanks in Advance..
Edit..
According to my study and knowledge. AppDelegate is a controller, it doesn't visually present data (a view) nor does it represent the actual data (a model) but it does determine what view controllers to show etc and manage other views (status bar etc) at the start of the application .it is the launcher class where the first class launches . it consist of some predefined function didFinishLauching and other functions. Is there any detail explanation.
From:
https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/AppArchitecture/AppArchitecture.html
The app delegate is a custom object created at app launch time,
usually by the UIApplicationMain function. The primary job of this
object is to handle state transitions within the app. For example,
this object is responsible for launch-time initialization and handling
transitions to and from the background. For information about how you
use the app delegate to manage state transitions, see “Managing App
State Changes.”
In iOS 5 and later, you can use the app delegate to handle other
app-related events. The Xcode project templates declare the app
delegate as a subclass of UIResponder. If the UIApplication object
does not handle an event, it dispatches the event to your app delegate
for processing. For more information about the types of events you can
handle, see UIResponder Class Reference.

Delegate of type 'required'

What in ios is a required delegate method?
Example:
CLLocationManagerDelegate
locationManagerDidPauseLocationUpdates:
Tells the delegate that location updates were paused. (required)
The question is related to the last word: '(required)'
I know that there are optional delegate methods, but what happens if I do not implement
all of the required delegates?
Especially I have not implemented the above method in my App which uses the LocationManager,
SDK is ios6, target = ios5.
Could my App crash if I do not implement that method?
I recently ported to ios6, but till now it did not crash!
Was that luck that the method had not been called, or is required a recommendation?
Update:
The info above is from ios6.1 Docu set.
When I open the ios6.1 header file
LocationManager.h:
* Discussion:
* Invoked when location updates are automatically paused.
*/
- (void)locationManagerDidPauseLocationUpdates:(CLLocationManager *)manager __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_6_0);
There is no hint for required, they are all under the #optional tag
It could crash is as close as we can get. Generally it means that if you don't implement it something won't work, but the documentation isn't as accurate as it could be. In some cases the class using the delegate doesn't check that the delegate actually implements the specified method so whenever it was called you'd get an exception. So, if the documentation says it's required it's best to implement it, even if your implementation is an empty method.
In this particular case, "locationManagerDidPauseLocationUpdates" is called on iOS 6 (and newer) OS'es to inform your app that the location isn't changing and that it's shutting down to save power.
On iOS 5, this delegate method won't get called but if you implement it, it will get called in iOS 6.
If you target iOS 6 (instead of iOS 5), you'll get a compiler warning if you didn't implement any "required" delegate methods.

iOS: Using UIApplicationDelegate Functions in an static library

I want to build a static library that catches incoming push notifications and uses the json objects outside the "aps" namespace. Is there any way to do this without changing the application:didReceiveRemoteNotification: method in the AppDelegate but by simply adding and using the static library?
Thanks in advance!
No, there isn't a way to do what you are asking (that I know of). First, you could do a class extension or category, but both would require the user to import them in the app delegate. Also, with that you could 'override' the method, but it wouldn't allow the user to 'use' that method in their app delegate (if they also wanted to perform some logic in the didReceiveRemoteNotification method).

Resources