cruffenach / CRToast

A modern iOS toast view that can fit your notification needs
MIT License
4.17k stars 463 forks source link

Crashes when creating larger toaster #215

Closed LucasVanDongen closed 7 years ago

LucasVanDongen commented 7 years ago

'NSInternalInconsistencyException', reason: 'Invalid size {320, 0} for item <CRToastView: 0x7fac30e10d70; frame = (0 0; 320 0); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x61000003ef80>> in Dynamics'

I'm not sure what's causing it to crash. Works fine as long as I don't use .custom but I need a bit more space to show a list of errors.

    let type: CRToastType = size == nil ? .navigationBar : .custom

    var options: [String: AnyObject] = [
        kCRToastTextKey: title as AnyObject,
        kCRToastTextAlignmentKey : NSTextAlignment.center as AnyObject,
        kCRToastBackgroundColorKey : color as AnyObject,
        kCRToastAnimationInTypeKey : NSNumber(value: CRToastAnimationType.gravity.rawValue),
        kCRToastAnimationOutTypeKey : NSNumber(value: CRToastAnimationType.gravity.rawValue),
        kCRToastAnimationInDirectionKey : NSNumber(value: CRToastAnimationDirection.top.rawValue),
        kCRToastAnimationOutDirectionKey : NSNumber(value: CRToastAnimationDirection.top.rawValue),
        kCRToastSubtitleTextKey: message as AnyObject,
        kCRToastTimeIntervalKey: 5.0 as AnyObject,
        kCRToastNotificationTypeKey: NSNumber(value: type.rawValue),
        kCRToastInteractionRespondersKey: interactions as NSArray,
        kCRToastNotificationPresentationTypeKey : NSNumber(value: CRToastPresentationType.cover.rawValue),
        kCRToastStatusBarStyleKey: true as AnyObject

    ]

    if let size = size {
        options[kCRToastNotificationPreferredHeightKey] = size as AnyObject
    }
LucasVanDongen commented 7 years ago

Solved. It expects everything wrapped in an NSNumber

Changed

       options[kCRToastNotificationPreferredHeightKey] = size as AnyObject

To

        options[kCRToastNotificationPreferredHeightKey] = NSNumber(value: size)

And it worked.

Note: I replaced all occurrences of primitives now, also the time interval and statusbar bool!