Bug 24016 - Missed bindings for UIObjectRestoration and UIViewControllerRestoration protocols
Summary: Missed bindings for UIObjectRestoration and UIViewControllerRestoration proto...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 8.0.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-10-23 13:00 UTC by Rustam Zaitov
Modified: 2015-03-03 11:25 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
sample with workaround (7.46 MB, application/zip)
2014-10-23 15:30 UTC, Rustam Zaitov
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Rustam Zaitov 2014-10-23 13:00:56 UTC
Working on sample I receive this warning:
"restoration class for object does not conform to UIObjectRestoration protocol: Class is DetailViewController"

My class looks like this:
[Adopts ("UIViewControllerRestoration")]
[Adopts("UIObjectRestoration")]
public partial class DetailViewController : UIViewController
{
	[Export ("objectWithRestorationIdentifierPath:coder:")]
	public static UIStateRestoring GetStateRestorationObjectFromPath (NSArray identifierComponents, NSCoder coder)
	{/* code here*/}

}

Alex Soto suggested to me rewrite class definition like this:
public partial class DetailViewController : UIViewController, IUIObjectRestoration, IUIViewControllerRestoration

But assembly doesn't contains IUIObjectRestoration, IUIViewControllerRestoration, UIObjectRestoration, UIViewControllerRestoration.

This may be the cause for this issue
https://bugzilla.xamarin.com/show_bug.cgi?id=17900
Comment 1 Rustam Zaitov 2014-10-23 15:28:57 UTC
I updated the problematic sample. Now it works with workaround

sample
https://github.com/xamarin/private-samples/tree/master/ios7/StateRestorationSample

workaround
https://gist.github.com/dalexsoto/0729c9c4e7f1f7196f82
Comment 2 Rustam Zaitov 2014-10-23 15:30:49 UTC
Created attachment 8484 [details]
sample with workaround
Comment 3 Alex Soto [MSFT] 2014-10-23 23:48:14 UTC
Hello Rustam I see now why they are not available as C# Interfaces

@protocol UIObjectRestoration
+ (id<UIStateRestoring>) objectWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder;
@end

It contains a static method and C# does not allow static methods inside interfaces.

Still I tried to repro the issue in comment #1 and commented static DetailViewController() implementation but I was not able to repro the warning "restoration class for object does not conform to UIObjectRestoration protocol: Class is DetailViewController"

Could you tell me how to repro that warning?
Comment 4 Rustam Zaitov 2014-10-24 08:19:55 UTC
Yes sure.
UIObjectRestoration – protocol for implementation iOS App's state Restoration feature. So we need to run preservation and then restoration process:
* Remove previous installation (preserved state will be removed)
* Run the app
* Choose some image within collectionView
* Tap on filter button (e.x. sepia)
* Change slider value (e.x. move to "Full" value)
* Tap on back button. Now you can see image with applied filter
* Move app to background (press home button). Here preservation begin
* Stop app via XS (!!! Don't stop the app via app switcher !!!)
* Run the app again. Restoration will begin. Crash with warning message is here

You need src not from zip, because zip contains app with applied fix (no crash here, no warnings). To see this warning you need to run sample without fix
repo: https://github.com/xamarin/private-samples
sample: StateRestorationSample
sha1: 4ff39ce61ac75ac741d4af6a7c5255f6cf5fae56
Comment 5 Alex Soto [MSFT] 2014-10-25 21:31:22 UTC
Now I can repro the warning

Warning: restoration class for object does not conform to UIObjectRestoration protocol: Class is DetailViewController

Trying

	[Adopts ("UIViewControllerRestoration")]
	[Adopts("UIObjectRestoration")]
	public partial class DetailViewController : UIViewController { ... }

or inside DetailViewController.cs

	static AdoptsAttribute uiVcRestorationProtocol = new AdoptsAttribute ("UIViewControllerRestoration");
	static AdoptsAttribute uiObjectRestorationProtocol = new AdoptsAttribute ("UIObjectRestoration");
	public override bool ConformsToProtocol (IntPtr protocol)
	{
		if (protocol == uiObjectRestorationProtocol.ProtocolHandle || 
			protocol == uiVcRestorationProtocol.ProtocolHandle)
			return true;
		return base.ConformsToProtocol (protocol);
	}

Won't work.

Objective C runtime seems to be checking class based conformsToProtocol instead of instance based one so workaround [1] is still required for it to work.

[1]: https://gist.github.com/dalexsoto/0729c9c4e7f1f7196f82
Comment 6 Alex Soto [MSFT] 2014-10-25 21:44:47 UTC
Btw this method **does** get called using the workaround[1] during the restoration process :)

https://github.com/xamarin/private-samples/blob/master/ios7/StateRestorationSample/StateRestorationSample/DetailViewController.cs#L314-L317

[1]: https://gist.github.com/dalexsoto/0729c9c4e7f1f7196f82
Comment 7 Rolf Bjarne Kvinge [MSFT] 2015-03-03 11:25:38 UTC
UIViewControllerRestoration added in maccore/master: 7dbfac0e58f61af31238f0cd21e402f54aae07e6.

The rest is a dup of bug #17900.