App crashes after Monotouch update to 5.2.13 - ios

After I have updated monotouch to Version 5.2.13 my App crashes when I touched inside a UIButton.
About my Code: (it's a question of a LoginView):
I have a UIViewController which includes a ScrollView.
For each User the ScrollView provides a UIView (the UserImageView).
This UserImageView contains a UserImage, Username and so on. Over the UserImage lays a UIButton which should catches the Touch-Events to selected a User.
This Button causes the Exception below more precisely the HitTest method from the UIView.
I get the following Stacktrace:
Stacktrace:
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) <IL 0x0009f, 0xffffffff>
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
at MF.Stationaer.iPad.Application.Main (string[]) <IL 0x00028, 0x00073>
at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
Native stacktrace:
0 MFiPad_MD 0x0009061c mono_handle_native_sigsegv + 284
1 MFiPad_MD 0x000059a8 mono_sigsegv_signal_handler + 248
2 libsystem_c.dylib 0x92cd259b _sigtramp + 43
3 ??? 0xffffffff 0x0 + 4294967295
4 UIKit 0x0228c741 __38-[UIView(Geometry) hitTest:withEvent:]_block_invoke_0 + 96
5 CoreFoundation 0x0116cf1a __NSArrayChunkIterate + 362
6 CoreFoundation 0x01138635 __NSArrayEnumerate + 997
7 CoreFoundation 0x01138026 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
8 UIKit 0x0228c66b -[UIView(Geometry) hitTest:withEvent:] + 646
9 UIKit 0x0228c765 __38-[UIView(Geometry) hitTest:withEvent:]_block_invoke_0 + 132
10 CoreFoundation 0x0116cf1a __NSArrayChunkIterate + 362
11 CoreFoundation 0x01138635 __NSArrayEnumerate + 997
12 CoreFoundation 0x01138026 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
13 UIKit 0x0228c66b -[UIView(Geometry) hitTest:withEvent:] + 646
14 UIKit 0x022a1157 -[UIScrollView hitTest:withEvent:] + 79
15 UIKit 0x0228c765 __38-[UIView(Geometry) hitTest:withEvent:]_block_invoke_0 + 132
16 CoreFoundation 0x0116cf1a __NSArrayChunkIterate + 362
17 CoreFoundation 0x01138635 __NSArrayEnumerate + 997
18 CoreFoundation 0x01138026 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
19 UIKit 0x0228c66b -[UIView(Geometry) hitTest:withEvent:] + 646
20 UIKit 0x0228c765 __38-[UIView(Geometry) hitTest:withEvent:]_block_invoke_0 + 132
21 CoreFoundation 0x0116cf1a __NSArrayChunkIterate + 362
22 CoreFoundation 0x01138635 __NSArrayEnumerate + 997
23 CoreFoundation 0x01138026 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
24 UIKit 0x0228c66b -[UIView(Geometry) hitTest:withEvent:] + 646
25 UIKit 0x0228c765 __38-[UIView(Geometry) hitTest:withEvent:]_block_invoke_0 + 132
26 CoreFoundation 0x0116cf1a __NSArrayChunkIterate + 362
27 CoreFoundation 0x01138635 __NSArrayEnumerate + 997
28 CoreFoundation 0x01138026 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 102
29 UIKit 0x0228c66b -[UIView(Geometry) hitTest:withEvent:] + 646
30 UIKit 0x02286dbd +[UIWindow _hitTestToPoint:pathIndex:forEvent:] + 378
31 UIKit 0x02258ca0 _UIApplicationHandleEvent + 1648
32 GraphicsServices 0x047c5ef5 PurpleEventCallback + 1274
33 CoreFoundation 0x011a9195 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
34 CoreFoundation 0x0110dff2 __CFRunLoopDoSource1 + 146
35 CoreFoundation 0x0110c8da __CFRunLoopRun + 2218
36 CoreFoundation 0x0110bd84 CFRunLoopRunSpecific + 212
37 CoreFoundation 0x0110bc9b CFRunLoopRunInMode + 123
38 GraphicsServices 0x047c47d8 GSEventRunModal + 190
39 GraphicsServices 0x047c488a GSEventRun + 103
40 UIKit 0x02258626 UIApplicationMain + 1163
41 ??? 0x0b96e514 0x0 + 194438420
42 ??? 0x0b96d6c0 0x0 + 194434752
43 ??? 0x0b96d33c 0x0 + 194433852
44 ??? 0x0b96d42f 0x0 + 194434095
45 MFiPad_MD 0x00009d12 mono_jit_runtime_invoke + 722
46 MFiPad_MD 0x00169e4e mono_runtime_invoke + 126
47 MFiPad_MD 0x0016df34 mono_runtime_exec_main + 420
48 MFiPad_MD 0x001732e5 mono_runtime_run_main + 725
49 MFiPad_MD 0x00066f15 mono_jit_exec + 149
50 MFiPad_MD 0x002115d5 main + 2837
51 MFiPad_MD 0x00002d65 start + 53
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
Here is the important Part of my Code:
public class LoginViewController : UIViewController
{
...
public override void ViewDidLoad()
{
...
BuildUserUI();
...
}
private void BuildUserUI()
{
currentIconLocation = new PointF(50, 10);
for (var i = 0; i < UserList.List.Count; i++)
CreateUserInGrid(UserList.GetUserByIndex(i));
}
private void CreateUserInGrid(LoginUser user)
{
var imgFrame = new RectangleF(currentIconLocation.X, currentIconLocation.Y, 140, 170);
var loginImg = new UILoginImage(imgFrame);
loginImg.Image = user.Image ?? defaultUserImage.CGImage;
loginImg.Name = user.Nachname;
if (!string.IsNullOrEmpty(user.Vorname))
loginImg.Name += ", " + user.Vorname;
loginImg.Tag = user.UserIndex;
loginImg.AddTarget(this, new Selector("ShowNumberPad:"), UIControlEvent.TouchUpInside);
loginImg.LoginUser = user;
scrollView.AddSubview(loginImg);
loginImages.Add(loginImg);
limitedScrollView.UserInteractionEnabled = false;
var newSize = new SizeF(scrollView.Frame.Size.Width, currentIconLocation.Y + imgFrame.Size.Height + 20);
scrollView.ContentSize = newSize;
limitedScrollView.ContentSize = new SizeF(limitedScrollView.Frame.Size.Width, limitedScrollView.Frame.Size.Height);
currentIconLocation.X += imgFrame.Size.Width;
if (currentIconLocation.X + imgFrame.Size.Width > scrollView.Frame.Size.Width)
{
currentIconLocation.Y += imgFrame.Size.Height;
currentIconLocation.X = 50;
}
}
[Export("ShowNumberPad:")]
private void ShowNumberPad(NSObject sender)
{
...
}
}
public class UILoginImage : UIView
{
[Export("initWithFrame:")]
public UILoginImage(RectangleF frame)
: base(frame)
{
var shadowFrame = new RectangleF(0, 0, 117, 148);
wrapperControl = new UIControl(shadowFrame);
AddSubview(wrapperControl);
shadowImage = new UIImageView(shadowFrame);
shadowImage.Image = ImageCache.GetResourceImage("Images/Login/LoginSchatten.png");
wrapperControl.AddSubview(shadowImage);
var mainBackFrame = new RectangleF(8, 9, 98, 128);
whiteBackgroundImage = new UIImageView(mainBackFrame);
whiteBackgroundImage.Image = ImageCache.GetResourceImage("Images/Login/Singlewhite.png");
wrapperControl.AddSubview(whiteBackgroundImage);
var imageFrame = new RectangleF(13, 15, 87, 116);
clickHelper = UIButton.FromType(UIButtonType.Custom);
clickHelper.Frame = imageFrame;
wrapperControl.AddSubview(clickHelper);
userImage = new UIImageView(imageFrame);
AddSubview(userImage);
var mitarbeiterlabelFrame = new RectangleF(-12, 137, 140, 25);
mitarbeiterNameLabel = new FontSizeLabel(mitarbeiterlabelFrame);
mitarbeiterNameLabel.TextAlignment = UITextAlignment.Center;
mitarbeiterNameLabel.Font = UIFont.SystemFontOfSize(12);
mitarbeiterNameLabel.Opaque = false;
mitarbeiterNameLabel.BackgroundColor = UIColor.Clear;
AddSubview(mitarbeiterNameLabel);
var benutzerlabelFrame = new RectangleF(mitarbeiterlabelFrame.X, mitarbeiterlabelFrame.Y + 13, 140, 25);
benutzerNameLabel = new FontSizeLabel(benutzerlabelFrame);
benutzerNameLabel.TextAlignment = UITextAlignment.Center;
benutzerNameLabel.Font = UIFont.SystemFontOfSize(10);
benutzerNameLabel.Opaque = false;
benutzerNameLabel.BackgroundColor = UIColor.Clear;
benutzerNameLabel.TextColor = UIColor.DarkGray;
AddSubview(benutzerNameLabel);
}
public void AddTarget(NSObject target, Selector action, UIControlEvent controlEvents)
{
clickHelper.AddTarget(target, action, controlEvents);
}
public void RemoveTarget(NSObject target, Selector action, UIControlEvent controlEvents)
{
clickHelper.RemoveTarget(target, action, controlEvents);
}
}

I'm not sure your use of AddTarget is a good way to hook up a UIButton's click.
You should be using clickHelper.TouchUpInside to wire up click events. This is a standard C# event.
Another option would be to wire up an action to this event inside your XIB file in XCode.

Related

NSInvalidArgumentException - Attempt to insert nil object from objects

I had the error below:
'*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[1]'
it happens when I try to save texts from textfields using saveInBackground or other kind of saving method of Parse. Because code is little, all code is pasted below:
#IBAction func onSave(_ sender: Any) {
let profile = PFObject(className: "Info")
profile["preferredName"] = nameTextField.text!
profile["major"] = majorTextField.text!
profile["introduction"] = bioTextView.text!
let segmentIndex = yearSegmented.selectedSegmentIndex
UserDefaults.standard.set(segmentIndex, forKey: "segmentIndex")
profile["year"] = yearSegmented.titleForSegment(at: segmentIndex)!
print(profile.allKeys) // print keys in profile
print(profile.value(forKey: "introduction")!, profile.value(forKey: "major")!,
profile.value(forKey: "year")!, profile.value(forKey: "preferredName")!) // print values in profile
profile.saveInBackground(block: { (success, error) in // line where the error happens
if success {
UserDefaults.standard.set(true, forKey: "hasProfile")
print("profile saved")
} else {
print("failed to save profile")
}
})
This is how Parse IOS Guide told me about how to save objects:
let gameScore = PFObject(className:"GameScore")
gameScore["score"] = 1337
gameScore["playerName"] = "Sean Plott"
gameScore["cheatMode"] = false
gameScore.saveInBackground { (succeeded, error) in
if (succeeded) {
// The object has been saved.
} else {
// There was a problem, check error.description
}
}
I tested if any content in profile is nil, but all keys and values are there and can be printed. I don't see anything nil here, so I cannot understand this error. If anyone could shed some light to enlighten me, I would be be very grateful for this.
In case anyone needs the stack trace:
0 CoreFoundation 0x00000001803f25e4 __exceptionPreprocess + 236
1 libobjc.A.dylib 0x000000018019813c objc_exception_throw + 56
2 CoreFoundation 0x00000001804775b4 -[__NSCFString characterAtIndex:].cold.1 + 0
3 CoreFoundation 0x0000000180474fc4 -[__NSPlaceholderArray initWithCapacity:].cold.1 + 0
4 CoreFoundation 0x00000001802ef138 -[__NSPlaceholderArray initWithObjects:count:] + 184
5 CoreFoundation 0x00000001803dddec +[NSArray arrayWithObjects:count:] + 44
6 Parse 0x0000000104eda478 -[PFTaskQueue enqueue:] + 380
7 Parse 0x0000000104e78b2c -[PFObject saveInBackground] + 148
8 Parse 0x0000000104e78c1c -[PFObject saveInBackgroundWithBlock:] + 68
9 StudyMate 0x00000001041c59bc $s9StudyMate18EditViewControllerC6onSaveyyypF + 7276
10 StudyMate 0x00000001041c5fe4 $s9StudyMate18EditViewControllerC6onSaveyyypFTo + 68
11 UIKitCore 0x0000000184d81fa0 -[UIApplication sendAction:to:from:forEvent:] + 96
12 UIKitCore 0x00000001842a7714 -[UIBarButtonItem _triggerActionForEvent:] + 176
13 UIKitCore 0x000000018427fe24 __45-[_UIButtonBarTargetAction _invoke:forEvent:]_block_invoke + 36
14 UIKitCore 0x000000018427fcd8 -[_UIButtonBarTargetAction _invoke:forEvent:] + 168
15 UIKitCore 0x0000000184d81fa0 -[UIApplication sendAction:to:from:forEvent:] + 96
16 UIKitCore 0x0000000184680bd8 -[UIControl sendAction:to:forEvent:] + 124
17 UIKitCore 0x0000000184680fc0 -[UIControl _sendActionsForEvents:withEvent:] + 352
18 UIKitCore 0x0000000184681010 -[UIControl _sendActionsForEvents:withEvent:] + 432
19 UIKitCore 0x000000018467f8e8 -[UIControl touchesEnded:withEvent:] + 516
20 UIKitCore 0x0000000184dc0af0 -[UIWindow _sendTouchesForEvent:] + 1104
21 UIKitCore 0x0000000184dc25d4 -[UIWindow sendEvent:] + 4332
22 UIKitCore 0x0000000184d9a390 -[UIApplication sendEvent:] + 784
23 UIKitCore 0x0000000184e286f4 __dispatchPreprocessedEventFromEventQueue + 7520
24 UIKitCore 0x0000000184e2a770 __processEventQueue + 6764
25 UIKitCore 0x0000000184e22760 __eventFetcherSourceCallback + 184
26 CoreFoundation 0x0000000180360820 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
27 CoreFoundation 0x0000000180360720 __CFRunLoopDoSource0 + 204
28 CoreFoundation 0x000000018035fab0 __CFRunLoopDoSources0 + 256
29 CoreFoundation 0x000000018035a004 __CFRunLoopRun + 744
30 CoreFoundation 0x0000000180359804 CFRunLoopRunSpecific + 572
31 GraphicsServices 0x000000018c23660c GSEventRunModal + 160
32 UIKitCore 0x0000000184d7bd2c -[UIApplication _run] + 992
33 UIKitCore 0x0000000184d808c8 UIApplicationMain + 112
34 libswiftUIKit.dylib 0x00000001b6766224 $s5UIKit17UIApplicationMainys5Int32VAD_SpySpys4Int8VGGSgSSSgAJtF + 100
35 StudyMate 0x00000001041c7a9c $sSo21UIApplicationDelegateP5UIKitE4mainyyFZ + 104
36 StudyMate 0x00000001041c7a24 $s9StudyMate11AppDelegateC5$mainyyFZ + 44
37 StudyMate 0x00000001041c7b20 main + 28
38 dyld 0x0000000104501cd8 start_sim + 20
39 ??? 0x0000000104451088 0x0 + 4366602376
40 ??? 0xb23a000000000000 0x0 + 12842577287400390656

NSAttributedString crash when converting HTML to Attrubuted String

I have a situation where try NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil) crashes the app.
In the console it says:
Assertion failure in void _prepareForCAFlush(UIApplication *__strong)()
The function is called in an extension String.
When I 'po' values in the console:
(lldb) po self
<p>Obfuscated string\n</p>
(lldb) po data`
450 bytes
count : 450
pointer : 0x00007fd283d75630
pointerValue : 140542131787312
(lldb) po NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
Obfuscated string
{
NSColor = "kCGColorSpaceModelRGB 0 0 0 1 ";
NSFont = "<UICTFont: 0x7fd283c47330> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 15.00pt";
NSKern = 0;
NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 15, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 19/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n), DefaultTabInterval 36, Blocks (\n), Lists (\n), BaseWritingDirection 0, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0";
NSStrokeColor = "kCGColorSpaceModelRGB 0 0 0 1 ";
NSStrokeWidth = 0;
}
The string exists in a label, that is displayed in a UITableViewCell.
The function crashes in a specific case, when the "keyboard frame changes".
The Table Cells are being drawn again by iOS and this causes to redraw their content.
The crash happens on the main thread, so the function is being called on the main thread.
What could be the cause of this crash and how could I possibly resolve it?
EDIT: Table view cell code
UITableViewDataSource to generate the cell:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellID = cellIdentifier(for: message)
let cell = tableView.dequeueReusableCell(withIdentifier: cellID) as! MessageTableViewCell
cell.message = message
cell.setOutletValues()
cell.selectionStyle = .none
cell.delegate = self
return cell
}
Implementaion of the Cell:
class MessageTableViewCell: UITableViewCell {
var message: Message!
// Message Body View
#IBOutlet weak var messageBodyView: ZeroPaddingTextView!
func setOutletValues() {
setMessageBodyOutletValues()
}
internal func setMessageBodyOutletValues() {
if let body = message.body {
messageBodyView.attributedText = body.htmlToPlainAttributedString()
}
}
}
And the function to create a plain attributed string, it does a few additions tothe HTML for styling (this is due to the content that comes in through the API, it needs some additions).
func htmlToPlainAttributedString() -> NSAttributedString {
let contentString = replacingOccurrences(of: "\n", with: "<br>")
let styleSheet = "body {font-family: sans-serif; font-size: 15px; color: #000000;}\n a {text-decoration: none;}\n"
let body = "<body>\(contentString)</body>"
let html = "<html><head><style type=\"text/css\">\(styleSheet)</style></head>\(body)</html>"
if let data = html.data(using: String.Encoding.unicode, allowLossyConversion: true) {
do {
return try NSAttributedString(data: data, options: [
NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil)
} catch {
return NSAttributedString()
}
}
return NSAttributedString()
}
Console crash output:
2017-09-05 22:37:14.692 trustedfamily-ios[70389:10080542] *** Assertion failure in void _prepareForCAFlush(UIApplication *__strong)(), /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.7.47/UIApplication.m:2395
2017-09-05 22:38:14.532 trustedfamily-ios[70389:10080542] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unexpected start state'
*** First throw call stack:
(
0 CoreFoundation 0x000000010452ab0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001035e8141 objc_exception_throw + 48
2 CoreFoundation 0x000000010452ecf2 +[NSException raise:format:arguments:] + 98
3 Foundation 0x00000001031b769b -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 165
4 UIKit 0x0000000105a31575 _prepareForCAFlush + 499
5 UIKit 0x0000000105a6346b _beforeCACommitHandler + 15
6 CoreFoundation 0x00000001044d0717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
7 CoreFoundation 0x00000001044d0687 __CFRunLoopDoObservers + 391
8 CoreFoundation 0x00000001044b5038 CFRunLoopRunSpecific + 440
9 UIFoundation 0x000000010a103edc -[NSHTMLReader _loadUsingWebKit] + 1954
10 UIFoundation 0x000000010a10522a -[NSHTMLReader attributedString] + 22
11 UIFoundation 0x000000010a09ded6 _NSReadAttributedStringFromURLOrData + 8926
12 UIFoundation 0x000000010a09bb64 -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithData:options:documentAttributes:error:] + 117
13 trustedfamily-ios 0x0000000101e9e6ad _TTOFE5UIKitCSo18NSAttributedStringcfzT4dataV10Foundation4Data7optionsGVs10DictionarySSP__18documentAttributesGSqGVs33AutoreleasingUnsafeMutablePointerGSqCSo12NSDictionary____S0_ + 173
14 trustedfamily-ios 0x0000000101e9d9d9 _TFE5UIKitCSo18NSAttributedStringCfzT4dataV10Foundation4Data7optionsGVs10DictionarySSP__18documentAttributesGSqGVs33AutoreleasingUnsafeMutablePointerGSqCSo12NSDictionary____S0_ + 89
15 trustedfamily-ios 0x0000000101e9d803 _TFE17trustedfamily_iosSS27htmlToPlainAttributedStringfT_CSo18NSAttributedString + 1459
16 trustedfamily-ios 0x00000001020152f9 _TFC17trustedfamily_ios20MessageTableViewCell26setMessageBodyOutletValuesfT_T_ + 601
17 trustedfamily-ios 0x0000000102013467 _TFC17trustedfamily_ios20MessageTableViewCell15setOutletValuesfT_T_ + 103
18 trustedfamily-ios 0x0000000101f9a22f _TFC17trustedfamily_ios32ConversationDetailViewController9tableViewfTCSo11UITableView12cellForRowAtV10Foundation9IndexPath_CSo15UITableViewCell + 1199
19 trustedfamily-ios 0x0000000101f9a4d7 _TToFC17trustedfamily_ios32ConversationDetailViewController9tableViewfTCSo11UITableView12cellForRowAtV10Foundation9IndexPath_CSo15UITableViewCell + 87
20 UIKit 0x0000000105ba4ab2 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 750
21 UIKit 0x0000000105ba4cf8 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
22 UIKit 0x0000000105b79639 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2845
23 UIKit 0x0000000105b774a4 -[UITableView _setNeedsVisibleCellsUpdate:withFrames:] + 201
24 UIKit 0x0000000105b9626a -[UITableView _rectChangedWithNewSize:oldSize:] + 1267
25 UIKit 0x0000000105b96a5c -[UITableView setBounds:] + 322
26 UIKit 0x0000000105adee73 -[UIView(Geometry) _applyISEngineLayoutValuesToBoundsOnly:] + 598
27 UIKit 0x0000000105adf15e -[UIView(Geometry) _resizeWithOldSuperviewSize:] + 125
28 UIKit 0x000000010648f0e9 -[UIScrollView(_UIOldConstraintBasedLayoutSupport) _resizeWithOldSuperviewSize:] + 46
29 CoreFoundation 0x00000001044bb652 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114
30 CoreFoundation 0x00000001044bb56f -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 335
31 UIKit 0x0000000105addbcc -[UIView(Geometry) resizeSubviewsWithOldSize:] + 183
32 UIKit 0x00000001063fa16d -[UIView(AdditionalLayoutSupport) _is_layout] + 168
33 UIKit 0x0000000105aea0a6 -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 994
34 UIKit 0x0000000105afb55b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1268
35 QuartzCore 0x00000001057a4904 -[CALayer layoutSublayers] + 146
36 QuartzCore 0x0000000105798526 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 370
37 UIKit 0x0000000105ae9334 -[UIView(Hierarchy) layoutBelowIfNeeded] + 1108
38 trustedfamily-ios 0x0000000101fe3f4c _TFC17trustedfamily_ios32ConversationDetailViewController28changeBottomLayoutConstraintfT2toV12CoreGraphics7CGFloat_T_ + 284
39 trustedfamily-ios 0x0000000101fe3fac _TToFC17trustedfamily_ios32ConversationDetailViewController28changeBottomLayoutConstraintfT2toV12CoreGraphics7CGFloat_T_ + 44
40 trustedfamily-ios 0x0000000101fe3bf7 _TFFC17trustedfamily_ios32ConversationDetailViewController28changeBottomLayoutConstraintFT2toV12CoreGraphics7CGFloat8animatedSb8durationSd7optionsVSC22UIViewAnimationOptions_T_U_FT_T_ + 39
41 trustedfamily-ios 0x0000000101e572d7 _TTRXFo___XFdCb___ + 39
42 UIKit 0x0000000105af13da +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 572
43 UIKit 0x0000000105af18dd +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] + 99
44 trustedfamily-ios 0x0000000101fe3b7f _TFC17trustedfamily_ios32ConversationDetailViewController28changeBottomLayoutConstraintfT2toV12CoreGraphics7CGFloat8animatedSb8durationSd7optionsVSC22UIViewAnimationOptions_T_ + 943
45 trustedfamily-ios 0x0000000101fe3e1f _TToFC17trustedfamily_ios32ConversationDetailViewController28changeBottomLayoutConstraintfT2toV12CoreGraphics7CGFloat8animatedSb8durationSd7optionsVSC22UIViewAnimationOptions_T_ + 79
46 trustedfamily-ios 0x0000000101fe30e6 _TFC17trustedfamily_ios32ConversationDetailViewController23keyboardWillChangeFramefV10Foundation12NotificationT_ + 2278
47 trustedfamily-ios 0x0000000101fe3237 _TToFC17trustedfamily_ios32ConversationDetailViewController23keyboardWillChangeFramefV10Foundation12NotificationT_ + 71
48 CoreFoundation 0x00000001044c9c2c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
49 CoreFoundation 0x00000001044c9b29 _CFXRegistrationPost + 425
50 CoreFoundation 0x00000001044c9892 ___CFXNotificationPost_block_invoke + 50
51 CoreFoundation 0x000000010448d102 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1826
52 CoreFoundation 0x000000010448c261 _CFXNotificationPost + 673
53 Foundation 0x00000001030b6ca4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
54 UIKit 0x000000010649ce05 -[UIInputWindowController postStartNotifications:withInfo:] + 225
55 UIKit 0x000000010649f0af __77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke.871 + 381
56 UIKit 0x0000000105af13da +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 572
57 UIKit 0x0000000105af1853 +[UIView(UIViewAnimationWithBlocks) _animateWithDuration:delay:options:animations:start:completion:] + 116
58 UIKit 0x000000010649eacb -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:] + 1503
59 UIKit 0x00000001064a6d5e __43-[UIInputWindowController setInputViewSet:]_block_invoke.1318 + 97
60 UIKit 0x000000010649a59a -[UIInputWindowController performOperations:withTemplateNotificationInfo:] + 46
61 UIKit 0x00000001064a68ea -[UIInputWindowController setInputViewSet:] + 1753
62 UIKit 0x000000010649e14c -[UIInputWindowController performOperations:withAnimationStyle:] + 50
63 UIKit 0x0000000106114a8a -[UIPeripheralHost(UIKitInternal) setInputViews:animationStyle:] + 1505
64 UIKit 0x0000000106115c4b -[UIPeripheralHost(UIKitInternal) _preserveInputViewsWithId:animated:reset:] + 499
65 UIKit 0x0000000105bec35d -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1145
66 UIKit 0x0000000105bedfae -[UIViewController _presentViewController:withAnimationController:completion:] + 4660
67 CoreFoundation 0x00000001044b2c6c __invoking___ + 140
68 CoreFoundation 0x00000001044b2b40 -[NSInvocation invoke] + 320
69 UIKit 0x0000000105bd1633 -[_UIDelayedPresentationContext finishDelayedPresentation:] + 230
70 UIKit 0x0000000105be9416 -[UIViewController _endDelayingPresentation] + 93
71 CoreFoundation 0x00000001044b2c6c __invoking___ + 140
72 CoreFoundation 0x00000001044b2b40 -[NSInvocation invoke] + 320
73 FrontBoardServices 0x000000010a1f25f6 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
74 FrontBoardServices 0x000000010a1f246d -[FBSSerialQueue _performNext] + 186
75 FrontBoardServices 0x000000010a1cb360 -[FBSWorkspace synchronizeSystemAnimationFencesWithCleanUpBlock:] + 1549
76 UIKit 0x0000000105a311d4 -[UIApplication _synchronizeSystemAnimationFencesWithSpinCleanUpBlock:] + 543
77 UIKit 0x0000000105ab22cd __realPreCommitHandler_block_invoke + 395
78 QuartzCore 0x000000010575532c _ZNK2CA11Transaction5Fence13run_callbacksEv + 40
79 QuartzCore 0x0000000105727f7c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 528
80 QuartzCore 0x0000000105754130 _ZN2CA11Transaction6commitEv + 468
81 QuartzCore 0x0000000105754b37 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 115
82 CoreFoundation 0x00000001044d0717 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
83 CoreFoundation 0x00000001044d0687 __CFRunLoopDoObservers + 391
84 CoreFoundation 0x00000001044b5720 __CFRunLoopRun + 1200
85 CoreFoundation 0x00000001044b5016 CFRunLoopRunSpecific + 406
86 GraphicsServices 0x000000010a9eda24 GSEventRunModal + 62
87 UIKit 0x0000000105a38134 UIApplicationMain + 159
88 trustedfamily-ios 0x0000000101ff6837 main + 55
89 libdyld.dylib 0x000000010894465d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Try to make your html convert in NSAttributedString inside
DispatchQueue.main.async {
}
I'm seeing this crash in a very similar situation in the field but can't reproduce it myself.
Let's try this and see if it helps:
guard UIApplication.shared.applicationState == .active else { return NSAttributedString() }

PageViewController on Xamarin will not load child content

I am quite new to mobile dev so forgive me if some of this seems trivial. But I am trying to get a basic PageViewController working in Xamarin iOS with a number of different sign up controllers I have, for different stages of the app signup. So a user will fill in page one, click continue and be taken to step two and so forth.
I used a sample PageViewController project from GitHub and got that working on my simulator fine. However when I try and use it with my sign up controllers, I get an error
Foundation.MonoTouchException: Objective-C exception thrown. Name:
NSUnknownKeyException Reason: [
setValue:forUndefinedKey:]: this class is not key value
coding-compliant for the key DateOfBirthText.
This is the parent view controller OnLoad method
public override void ViewDidLoad()
{
base.ViewDidLoad();
_pageViewController = Storyboard.InstantiateViewController("SignInPageViewController") as UIPageViewController;
_pageViewController.DataSource = new PageViewControllerDataSource(this, _userInput);
var startVc = ViewControllerAtIndex(0);
var viewControllers = new[] {startVc};
_pageViewController.SetViewControllers(viewControllers, UIPageViewControllerNavigationDirection.Forward, false, null);
_pageViewController.View.Frame = new CGRect(0, 0, View.Frame.Width, View.Frame.Size.Height - 50);
AddChildViewController(_pageViewController);
View.AddSubview(_pageViewController.View);
_pageViewController.DidMoveToParentViewController(this);
}
It throws the error on line
_pageViewController.SetViewControllers
And this is the designer code for the child controller that tries to be loaded into the PageViewController and throws the error
{
[Register ("SigninViewControllerStageOne")]
partial class SigninViewControllerStageOne
{
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UITextField DateOfBirthText { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UITextField NameText { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UIButton NextStepButton { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UITextField PhoneNumberText { get; set; }
[Outlet]
[GeneratedCode ("iOS Designer", "1.0")]
UILabel TitleLabel { get; set; }
void ReleaseDesignerOutlets ()
{
if (DateOfBirthText != null) {
DateOfBirthText.Dispose ();
DateOfBirthText = null;
}
if (NameText != null) {
NameText.Dispose ();
NameText = null;
}
if (NextStepButton != null) {
NextStepButton.Dispose ();
NextStepButton = null;
}
if (PhoneNumberText != null) {
PhoneNumberText.Dispose ();
PhoneNumberText = null;
}
if (TitleLabel != null) {
TitleLabel.Dispose ();
TitleLabel = null;
}
}
}
}
Update: Full stack trace
Unhandled Exception:
Foundation.MonoTouchException: Objective-C exception thrown. Name:
NSUnknownKeyException Reason: [
setValue:forUndefinedKey:]: this class is not key value
coding-compliant for the key DateOfBirthText.
Native stack trace:
0 CoreFoundation 0x00958494
__exceptionPreprocess + 180
1 libobjc.A.dylib 0x08fd3e02
objc_exception_throw + 50
2 CoreFoundation 0x009580b1 -[NSException
raise] + 17
3 Foundation 0x014777f8
-[NSObject(NSKeyValueCoding) setValue:forUndefinedKey:] + 282
4 Foundation 0x013d1e6a
_NSSetUsingKeyValueSetter + 115
5 Foundation 0x013d1def
-[NSObject(NSKeyValueCoding) setValue:forKey:] + 295
6 UIKit 0x0397b931 -[UIViewController
setValue:forKey:] + 85
7 Foundation 0x0140654b
-[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 384
8 UIKit 0x03bf8a62
-[UIRuntimeOutletConnection connect] + 132
9 libobjc.A.dylib 0x08fe800c -[NSObject
performSelector:] + 62
10 CoreFoundation 0x00881131 -[NSArray
makeObjectsPerformSelector:] + 273
11 UIKit 0x03bf70fc -[UINib
instantiateWithOwner:options:] + 2102
12 UIKit 0x03983380 -[UIViewController
_loadViewFromNibNamed:bundle:] + 429
13 UIKit 0x03983db8 -[UIViewController
loadView] + 189
14 UIKit 0x039841c4 -[UIViewController
loadViewIfRequired] + 154
15 UIKit 0x03984ab1 -[UIViewController
view] + 35
16 UIKit 0x04038649
-[UIPageViewController _setViewControllers:withCurlOfType:fromLocation:direction:animated:notifyDelegate:completion:]
+ 2250
17 UIKit 0x0403a76a
-[UIPageViewController setViewControllers:direction:animated:completion:] + 309
18 ??? 0x1a6a07cc 0x0 + 443156428
19 ??? 0x1a69f6d0 0x0 + 443152080
20 ??? 0x18d3200f 0x0 + 416489487
21 ??? 0x18d29c1d 0x0 + 416455709
22 BarPandaApp 0x001be859
mono_jit_runtime_invoke + 921
23 BarPandaApp 0x0027d0ce
mono_runtime_invoke + 142
24 BarPandaApp 0x0035e225 xamarin_trampoline
+ 5605
25 UIKit 0x0397fb72 -[UIViewController
_sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 44
26 UIKit 0x03984692 -[UIViewController
loadViewIfRequired] + 1384
27 UIKit 0x039d02bb
-[UINavigationController _layoutViewController:] + 52
28 UIKit 0x039d0b75
-[UINavigationController _updateScrollViewFromViewController:toViewController:] + 421
29 UIKit 0x039d0d1c
-[UINavigationController _startTransition:fromViewController:toViewController:] + 145
30 UIKit 0x039d2118
-[UINavigationController _startDeferredTransitionIfNeeded:] + 1038
31 UIKit 0x039d339e
-[UINavigationController __viewWillLayoutSubviews] + 68
32 UIKit 0x03bb84b7
-[UILayoutContainerView layoutSubviews] + 252
33 UIKit 0x038843d4
-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 810
34 libobjc.A.dylib 0x08fe8059 -[NSObject
performSelector:withObject:] + 70
35 QuartzCore 0x0b607096 -[CALayer
layoutSublayers] + 144
36 QuartzCore 0x0b5fa8b6
_ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 388
37 QuartzCore 0x0b5fa71a
_ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
38 QuartzCore 0x0b5ecee7
_ZN2CA7Context18commit_transactionEPNS_11TransactionE + 317
39 QuartzCore 0x0b621847
_ZN2CA11Transaction6commitEv + 561
40 QuartzCore 0x0b622108
_ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
41 CoreFoundation 0x0086a75e
CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30
42 CoreFoundation 0x0086a6be
__CFRunLoopDoObservers + 398
43 CoreFoundation 0x0085f868
CFRunLoopRunSpecific + 504
44 CoreFoundation 0x0085f65b CFRunLoopRunInMode
+ 123
45 UIKit 0x037ae2da -[UIApplication
_run] + 540
46 UIKit 0x037b3eb9 UIApplicationMain
+ 160
47 ??? 0x18d27144 0x0 + 416444740
48 ??? 0x18d26ef4 0x0 + 416444148
49 ??? 0x18d249a0 0x0 + 416434592
50 ??? 0x18d24620 0x0 + 416433696
51 ??? 0x18d24823 0x0 + 416434211
52 BarPandaApp 0x001be859
mono_jit_runtime_invoke + 921
53 BarPandaApp 0x0027d0ce
mono_runtime_invoke + 142
54 BarPandaApp 0x002822d1
mono_runtime_exec_main + 401
55 BarPandaApp 0x00282095
mono_runtime_run_main + 645
56 BarPandaApp 0x0013a3d5 mono_jit_exec +
213
57 BarPandaApp 0x0036d73a xamarin_main +
2474
58 BarPandaApp 0x0036e351 main + 65
59 libdyld.dylib 0x094ada25 start + 1
Actually, I don't think you should use UIPageViewController to implement the sign up progress.
But if you just need it, there is a sample I wrote for other, you can check this link to get it:
xamarin.ios implement PageController with images only code
I suggest you to use UINavigationController, It can make all you need, there is an example:
This is the code for AppDelegate(override the method "FinishedLaunching"):
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
SignUpStepViewController step1 = new SignUpStepViewController (1, UIColor.Red);
SignUpStepViewController step2 = new SignUpStepViewController (2, UIColor.Green);
SignUpStepViewController step3 = new SignUpStepViewController (3, UIColor.Blue);
step1.SetNextController(step2);
step2.SetNextController(step3);
UINavigationController myNavigationController = new UINavigationController (step1);
this.Window = new UIWindow (UIScreen.MainScreen.Bounds);
this.Window.RootViewController = myNavigationController;
this.Window.MakeKeyAndVisible ();
return true;
}
This is the code for SignUpStepViewController:
public class SignUpStepViewController : UIViewController
{
public SignUpStepViewController (int index,UIColor color)
{
this.Title = "Step " + index;
this.View.BackgroundColor = color;
}
public void SetNextController(SignUpStepViewController nextC)
{
UIBarButtonItem btnContinue = new UIBarButtonItem ("Continue",UIBarButtonItemStyle.Done, delegate {
this.NavigationController.PushViewController(nextC,true);
});
this.NavigationItem.SetRightBarButtonItem (btnContinue,true);
}
}
Hope it can help you.
If you still need help, just leave the message here, I will check latter.

AWS batchGetItem NSInvalidArgumentException JSONKeyPathsByPropertyKey: unrecognized selector

I'm trying to get some rows from DynamoDB in a Swift application. At the very last line in my code below I get a NSInvalidArgumentException. I think it must be because my request is not formatted correctly, but I don't know what is wrong. In the docs (batch operation sample) for the java sdk they use TableKeysAndAttributes, which doesn't seem to exist in the iOS SDK.
Here is my code:
var venueIdAttribute = AWSDynamoDBAttributeValue()
venueIdAttribute.N = "2164156"
var venueIdCondition = AWSDynamoDBCondition()
venueIdCondition.comparisonOperator = .EQ // Hash Key must always be Equals
venueIdCondition.attributeValueList = [venueIdAttribute]
var startDateAttribute = AWSDynamoDBAttributeValue()
var startString = String(format:"%1.0f", lastSyncDate.timeIntervalSince1970 * 1000)
startDateAttribute.N = String(format:"%1.0f", lastSyncDate.timeIntervalSince1970 * 1000)
var dateCondition = AWSDynamoDBCondition()
dateCondition.comparisonOperator = .GT
dateCondition.attributeValueList = [startDateAttribute];
var keysArray : NSArray = [["venueId" : venueIdCondition, "dateInterval" : dateCondition]]
var tableDict : NSDictionary = ["Keys":keysArray]
var requestMap : NSDictionary = ["myTable":tableDict]
var request : AWSDynamoDBBatchGetItemInput = AWSDynamoDBBatchGetItemInput()
request.requestItems = requestMap
request.returnConsumedCapacity = AWSDynamoDBReturnConsumedCapacity.Total
var response : BFTask = dynamoDB.batchGetItem(request) // This is synchronous
Here is the error:
2014-12-18 13:23:17.002 TouchDashboard[8066:503166] +[NSDictionaryI JSONKeyPathsByPropertyKey]: unrecognized selector sent to class 0x10a9930e8
2014-12-18 13:23:17.010 TouchDashboard[8066:503166] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[__NSDictionaryI JSONKeyPathsByPropertyKey]: unrecognized selector sent to class 0x10a9930e8'
*** First throw call stack:
(
0 CoreFoundation 0x000000010a6ebf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010c5b1bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010a6f2f4d +[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010a64b27c ___forwarding_ + 988
4 CoreFoundation 0x000000010a64ae18 _CF_forwarding_prep_0 + 120
5 TouchDashboard 0x0000000109b1176a -[MTLJSONAdapter initWithModel:] + 490
6 TouchDashboard 0x0000000109b0fc47 +[MTLJSONAdapter JSONDictionaryFromModel:] + 87
7 TouchDashboard 0x00000001099a47c5 +[AZModelUtility JSONDictionaryFromMapMTLDictionary:] + 517
8 TouchDashboard 0x0000000109a91c5b 59+[AWSDynamoDBBatchGetItemInput requestItemsJSONTransformer]_block_invoke_2 + 75
9 TouchDashboard 0x0000000109b21718 -[MTLReversibleValueTransformer reverseTransformedValue:] + 88
10 TouchDashboard 0x0000000109b11b90 __32-[MTLJSONAdapter JSONDictionary]_block_invoke + 480
11 CoreFoundation 0x000000010a62d766 __65-[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:]_block_invoke + 102
12 CoreFoundation 0x000000010a62d66c -[__NSDictionaryM enumerateKeysAndObjectsWithOptions:usingBlock:] + 204
13 TouchDashboard 0x0000000109b1192c -[MTLJSONAdapter JSONDictionary] + 300
14 TouchDashboard 0x0000000109b0fc5b +[MTLJSONAdapter JSONDictionaryFromModel:] + 107
15 TouchDashboard 0x00000001099a6829 -[AWSDynamoDB invokeRequest:HTTPMethod:URLString:targetPrefix:operationName:outputClass:] + 313
16 TouchDashboard 0x00000001099a6bd9 -[AWSDynamoDB batchGetItem:] + 153
17 TouchDashboard 0x000000010991a0d7 _TFC14TouchDashboard14ViewController9batchSyncfS0_FT_T_ + 10663
18 TouchDashboard 0x0000000109917349 _TFC14TouchDashboard14ViewController11viewDidLoadfS0_FT_T_ + 1161
19 TouchDashboard 0x0000000109917462 _TToFC14TouchDashboard14ViewController11viewDidLoadfS0_FT_T_ + 34
20 UIKit 0x000000010b41ea90 -[UIViewController loadViewIfRequired] + 738
21 UIKit 0x000000010b41ec8e -[UIViewController view] + 27
22 UIKit 0x000000010b33dca9 -[UIWindow addRootViewControllerViewIfPossible] + 58
23 UIKit 0x000000010b33e041 -[UIWindow _setHidden:forced:] + 247
24 UIKit 0x000000010b34a72c -[UIWindow makeKeyAndVisible] + 42
25 UIKit 0x000000010b2f5061 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628
26 UIKit 0x000000010b2f7d2c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
27 UIKit 0x000000010b2f6bf2 -[UIApplication workspaceDidEndTransaction:] + 179
28 FrontBoardServices 0x000000010ebe92a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
29 CoreFoundation 0x000000010a62153c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK + 12
30 CoreFoundation 0x000000010a617285 __CFRunLoopDoBlocks + 341
31 CoreFoundation 0x000000010a616a43 __CFRunLoopRun + 851
32 CoreFoundation 0x000000010a616486 CFRunLoopRunSpecific + 470
33 UIKit 0x000000010b2f6669 -[UIApplication _run] + 413
34 UIKit 0x000000010b2f9420 UIApplicationMain + 1282
35 TouchDashboard 0x000000010992ba2e top_level_code + 78
36 TouchDashboard 0x000000010992ba6a main + 42
37 libdyld.dylib 0x000000010cd8b145 start + 1
38 ??? 0x0000000000000001 0x0 + 1
AWSDynamoDBBatchGetItemInput's requestItems property needs to be a dictionary of the following key/value pair:
NSString (a table name) : AWSDynamoDBKeysAndAttributes (KeysAndAttributes)
Currently, you are passing an instance of NSDictionary as a value. Once you update your code snippet to use AWSDynamoDBKeysAndAttributes, it should work.

MonoTouch SIGSEGV during garbage collector initiated Dispose on ABPeoplePickerNavigationController

Building against MT 6.0.4.
Targeting iOS 4.
Testing on an iPhone 4S.
I'm stumped as to what I am doing wrong. I display the ABPeoplePickerNavigationController modally after subscribing to the SelectPerson event. Within the event, I take a copy of the data I need (only holding references to strings, not to any of the AdressBook or Person instances), and then close the modal dialog:
private string selectedPersonFirstName;
private string selectedPersonEmail;
private string selectedPersonPhone;
private void SelectContact()
{
var peoplePicker = new ABPeoplePickerNavigationController();
peoplePicker.Cancelled += (sender, e) =>
{
selectedPersonFirstName = null;
selectedPersonEmail = null;
selectedPersonPhone = null;
peoplePicker.DismissViewController(true, null);
};
peoplePicker.SelectPerson += (sender, e) =>
{
var selectedName = String.Format("{0} {1}", e.Person.FirstName, e.Person.LastName);
selectedPersonFirstName = e.Person.FirstName;
if ( e.Person.GetEmails().Count > 0)
selectedPersonEmail = e.Person.GetEmails().FirstOrDefault().Value;
if ( e.Person.GetPhones().Count > 0)
selectedPersonPhone = e.Person.GetPhones().FirstOrDefault().Value;
peoplePicker.DismissViewController(true, null);
};
PresentViewController(peoplePicker, true, null);
}
At some point later when the GC kicks in, it crashes:
Stacktrace:
at MonoTouch.Foundation.NSObject.FinishDispose () [0x0000b] in /Developer/MonoTouch/Source/monotouch/src/Foundation/NSObject.cs:158
at MonoTouch.Foundation.NSObject/MonoTouch_Disposer.Drain (MonoTouch.Foundation.NSObject) [0x00062] in /Developer/MonoTouch/Source/monotouch/src/Foundation/NSObject.cs:376
at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>
at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at MyApp.iOS.Application.Main (string[]) [0x00000] in /Users/tyson/Code/MyApp/iOS/Main.cs:19
at (wrapper runtime-invoke) object.runtime_invoke_dynamic (intptr,intptr,intptr,intptr) <0xffffffff>
Native stacktrace:
0 MyAppName--------------- 0x00f574f4 mono_handle_native_sigsegv + 280
1 MyAppName--------------- 0x00f3a2b8 mono_sigsegv_signal_handler + 268
2 libsystem_c.dylib 0x31ae97ed _sigtramp + 48
3 CoreFoundation 0x3745b2e7 CFRelease + 94
4 AddressBookUI 0x373922d1 -[ABGroupWrapper dealloc] + 100
5 libobjc.A.dylib 0x35a14175 _objc_rootRelease + 36
6 AddressBookUI 0x373a3f57 -[ABModel dealloc] + 146
7 libobjc.A.dylib 0x35a14175 _objc_rootRelease + 36
8 AddressBookUI 0x373aec43 -[ABAbstractViewController dealloc] + 38
9 AddressBookUI 0x373aeb3d -[ABMembersViewController dealloc] + 216
10 libobjc.A.dylib 0x35a14175 _objc_rootRelease + 36
11 CoreFoundation 0x3745b2e7 CFRelease + 94
12 CoreFoundation 0x3747106b -[__NSArrayM dealloc] + 122
13 libobjc.A.dylib 0x35a14175 _objc_rootRelease + 36
14 UIKit 0x33c891b9 -[UIViewController dealloc] + 496
15 UIKit 0x33c88f2f -[UINavigationController dealloc] + 198
16 AddressBookUI 0x373adcbd -[ABPeoplePickerNavigationController dealloc] + 376
17 libobjc.A.dylib 0x35a14175 _objc_rootRelease + 36
18 MyAppName--------------- 0x001e1ccc wrapper_managed_to_native_MonoTouch_ObjCRuntime_Messaging_void_objc_msgSend_intptr_intptr + 68
19 MyAppName--------------- 0x001ad49c MonoTouch_Foundation_NSObject_MonoTouch_Disposer_Drain_MonoTouch_Foundation_NSObject + 364
20 MyAppName--------------- 0x006997b8 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
21 MyAppName--------------- 0x00f3c6a4 mono_jit_runtime_invoke + 1644
22 MyAppName--------------- 0x00ff5dc0 mono_runtime_invoke + 128
23 MyAppName--------------- 0x00f2c6ec native_to_managed_trampoline_MonoTouch_Foundation_NSObject_MonoTouch_Disposer_Drain + 280
24 CoreFoundation 0x374a0eef +[NSObject performSelector:withObject:] + 42
25 Foundation 0x37d51747 __NSThreadPerformPerform + 350
26 CoreFoundation 0x374e6ad3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
27 CoreFoundation 0x374e629f __CFRunLoopDoSources0 + 214
28 CoreFoundation 0x374e5045 __CFRunLoopRun + 652
29 CoreFoundation 0x374684a5 CFRunLoopRunSpecific + 300
30 CoreFoundation 0x3746836d CFRunLoopRunInMode + 104
31 GraphicsServices 0x32375439 GSEventRunModal + 136
32 UIKit 0x33bece7d UIApplicationMain + 1080
33 MyAppName--------------- 0x001e6ca4 wrapper_managed_to_native_MonoTouch_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 240
34 MyAppName--------------- 0x00ee0210 MyApp_iOS_Application_Main_string__ + 152
35 MyAppName--------------- 0x006997b8 wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
36 MyAppName--------------- 0x00f3c6a4 mono_jit_runtime_invoke + 1644
37 MyAppName--------------- 0x00ff5dc0 mono_runtime_invoke + 128
38 MyAppName--------------- 0x00ffa224 mono_runtime_exec_main + 436
39 MyAppName--------------- 0x00fff770 mono_runtime_run_main + 756
40 MyAppName--------------- 0x00f434a4 mono_jit_exec + 140
41 MyAppName--------------- 0x0105c04c main + 2028
42 MyAppName--------------- 0x0001bd18 start + 40
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
Has anyone seen anything like this before? I'm up for workarounds at this point as I need it more reliable for a demo ASAP (not for app store submission yet).
It looks like a bug. Something gets released one time too many and crash.
You can, for your demonstration purpose, work around it by defining CFRetain like this:
[System.Runtime.InteropServices.DllImport ("/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")]
static extern IntPtr CFRetain (IntPtr obj);
and use it on the _AddressBook, like that
peoplePicker.SelectPerson += (sender, e) => {
CFRetain (peoplePicker._AddressBook);
var selectedName = String.Format("{0} {1}", e.Person.FirstName, e.Person.LastName);
...
That will balance the count and avoid the crash.
Update: bug filled, you can c.c. yourself the the bug report to know when a fix will be released.

Resources