Closed amitpdev closed 12 years ago
I was able to solve this issue, it was bad practice on my side. I'm using JC in a non-ARC project. Xcode forced me to include a more specific property declaration on: @property (nonatomic) JCNotificationBannerTapHandlingBlock tapHandler;
So I modified it to: @property (nonatomic, strong) JCNotificationBannerTapHandlingBlock tapHandler;
All was okay and working under Xcode 4.5.1 on my ML desktop. but running same project under Xcode 4.2 SL laptop crashed.
Anyway it turns out that 'copy' is the right way to go: @property (nonatomic, copy) JCNotificationBannerTapHandlingBlock tapHandler;
So its a good note for any of you who runs JC in non-ARC project.
wiki ? :)
Does this happen in the simulator as well? I haven't tested on anything below 5.1; I'm currently downloading the 5.0 simulator as I don't currently have any devices running anything below 5.1.
Edit: I didn't see your newest post until after I clicked comment.
Are you using the latest code? My copy has:
@property (nonatomic, strong) JCNotificationBannerTapHandlingBlock tapHandler;
rather than
@property (nonatomic) JCNotificationBannerTapHandlingBlock tapHandler;
Assuming you use the first form, I believe it should work without "copy" as long as you have ARC enabled on the files from this library (I mention this in the README.) Have you enabled ARC on the JC* files? If not, you'll have memory leaks in your project as well as bugs like this one.
I'm updating the README to link to instructions for enabling ARC per file with the following text:
You can enabled ARC per-file by adding the -fobjc-arc flag, as described on a common StackOverflow question.
Hi James,
Yes, i've enabled -fobjc-arc on all .m JC files. All projects settings are okay. The crash most probably happens due to 'strong' property. Not why it compiling with Xcode 4.5.1 is bulletproof to that issue.
I really recommend you modify your code to 'copy'. ( when I forked, it was just (nonatomic) )
see this thread for example: http://stackoverflow.com/questions/12061756/blocks-and-arc-copy-or-crash-with-release-build-caused-by-optimization-level
Also, I was looking on other "famos" projects and they all seem to use 'copy': https://github.com/tonymillion/Reachability
On Tue, Oct 30, 2012 at 4:41 PM, James Coleman notifications@github.comwrote:
Are you using the latest code? My copy has:
@property (nonatomic, strong) JCNotificationBannerTapHandlingBlock tapHandler;
rather than
@property (nonatomic) JCNotificationBannerTapHandlingBlock tapHandler;
Assuming you use the first form, I believe it should work without "copy" as long as you have ARC enabled on the files from this library (I mention this in the README.) Have you enabled ARC on the JC* files? If not, you'll have memory leaks in your project as well as bugs like this one.
I'm updating the README to link to instructions for enabling ARC per file with the following text:
You can enabled ARC per-file by adding the -fobjc-arc flag, as described on a common StackOverflow questionhttp://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project .
— Reply to this email directly or view it on GitHubhttps://github.com/jcoleman/JCNotificationBannerPresenter/issues/2#issuecomment-9912966.
Interesting, if you read further in the thread on SO it appears that strong
should work. It appears to be a compiler bug (http://stackoverflow.com/a/12063130/1114761) which is probably why it works on the newer versions of Xcode.
Edit: That is, strong
should copy the block if necessary. Apparently there was a known issue with a previous version of the compiler that didn't do this correctly.
If that is the case, would you consider support for earlier Xcode versions on this project ? I'm willing to test on each release. Please make the 'copy' change so I can stop using my fork and sync directly from master.
I've updated the code to use copy
property assignment semantics. Unfortunately the Apple/Clang ARC docs aren't incredibly clear what should/shouldn't be required. It seems that strong
should work as long as it's a property typed as a block (not at id
as in the case of NSMutableArray#addObject:), but given the apparent compiler bugs I'll just leave it as copy
for now.
When compiled with SDK 5.0, the following exception occurs once banner is displayed:
objc_msgSend + 36, stop reason = EXC_BAD_ACCESS (code=1, address=0x8308758b) frame #0: 0x023650b0 libobjc.A.dylib
objc_msgSend + 36 frame #1: 0x02365d40 libobjc.A.dylibobjc_retain + 48 frame #2: 0x001424e3 Bbx
-[JCNotificationBannerPresenter presentNotification:] + 2451 at JCNotificationBannerPresenter.m:124 frame #3: 0x00141a84 Bbx__61-[JCNotificationBannerPresenter beginPresentingNotifications]_block_invoke_0 + 148 at JCNotificationBannerPresenter.m:75 frame #4: 0x01fdc445 libdispatch.dylib
_dispatch_call_block_and_release + 15 frame #5: 0x01fde4f0 libdispatch.dylib_dispatch_main_queue_callback_4CF + 327 frame #6: 0x020f8833 CoreFoundation
__CFRunLoopRun + 2003 frame #7: 0x020f7db4 CoreFoundationCFRunLoopRunSpecific + 212 frame #8: 0x020f7ccb CoreFoundation
CFRunLoopRunInMode + 123 frame #9: 0x0253f879 GraphicsServicesGSEventRunModal + 207 frame #10: 0x0253f93e GraphicsServices
GSEventRun + 114 frame #11: 0x006b8a9b UIKitUIApplicationMain + 1175 frame #12: 0x00002146 Bbx
main + 134 at main.m:14