RestKit Mapping deallocated in background ?
-
27-10-2019 - |
문제
I have the following structure in my app (iPad, iOS 5):
UIView1 --> UIView2 (presented modal).
I have a custom class dealing with a REST Service. This Class handles all the mapping, routing, etc. needed. There is an object in UIView1 using this class.
From UIView1 i present the UIView2 (modal) which has a UIWebView included, showing some HTML Content and some PDF Documents (depending what was chosen in UIView1 by the User).
Sometimes it looks like UIView1 get'S deallocated in background while the user is in UIView2.
If the User now closes UIView2 to return to UIView1, the app crashes. The Error is kind of "RestKit Mapping for ... exists".
It looks to me, that UIView1 was deallocated, and now is build up in background, but the RestKit object still lives. RestKit is a Shared Object (Singleton).
What is the correct way to get this runnning?
해결책
The viewDidLoad
is not a good place to set up RestKit mappings - this method may be called multiple times within a lifetime of the controller.
A good (and safe) place to initialize RestKit and set up all the mappings is - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
in your AppDelegate. This way you can be sure the set up process is done just once and before any potential request may be sent.