hyperlab / TiMixpanel

Mixpanel integration for Titanium Mobile
22 stars 12 forks source link

App crashes when in app notification is triggered #4

Closed wienke closed 9 years ago

wienke commented 10 years ago

I get the following error log:

May  1 13:07:54 Download-WappZappTV WappZapp[16013] <Warning>: [ERROR] The application has crashed with an uncaught exception 'NSInvalidArgumentException'.
    Reason:
    Could not find a storyboard named 'MPNotification' in bundle NSBundle </var/mobile/Applications/476AB2A6-BBFB-4256-A644-F06EE1B131C8/WappZapp.app> (loaded)
    Stack trace:

    0   CoreFoundation                      0x303d9f03 <redacted> + 130
    1   libobjc.A.dylib                     0x3ab6ece7 objc_exception_throw + 38
    2   UIKit                               0x330dae89 <redacted> + 0
    3   WappZapp                            0x00313895 _ZN3WTI13tryMakeStringIPKcN2TI7UStringES2_EENS_10PassRefPtrINS_10StringImplEEET_T0_T1_ + 563620
    4   WappZapp                            0x00313773 _ZN3WTI13tryMakeStringIPKcN2TI7UStringES2_EENS_10PassRefPtrINS_10StringImplEEET_T0_T1_ + 563330
    5   libdispatch.dylib                   0x3b057d53 <redacted> + 10
    6   libdispatch.dylib                   0x3b057d3f <redacted> + 22
    7   libdispatch.dylib                   0x3b05a6c3 _dispatch_main_queue_callback_4CF + 278
    8   CoreFoundation                      0x303a4679 <redacted> + 8
    9   CoreFoundation                      0x303a2f45 <redacted> + 1308
    10  CoreFoundation                      0x3030d7a9 CFRunLoopRunSpecific + 524
    11  CoreFoundation                      0x3030d58b CFRunLoopRunInMode + 106
    12  GraphicsServices                    0x3527a6d3 GSEventRunModal + 138
    13  UIKit                               0x32c6c891 UIApplicationMain + 1136
    14  WappZapp                            0x000b5a23 WappZapp + 23075
    15  libdyld.dylib                       0x3b06cab7 <redacted> + 2
May  1 13:07:54 Download-WappZappTV WappZapp[16013] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'MPNotification' in bundle NSBundle </var/mobile/Applications/476AB2A6-BBFB-4256-A644-F06EE1B131C8/WappZapp.app> (loaded)'
    *** First throw call stack:
    (0x303d9f03 0x3ab6ece7 0x330dae89 0x313895 0x313773 0x3b057d53 0x3b057d3f 0x3b05a6c3 0x303a4679 0x303a2f45 0x3030d7a9 0x3030d58b 0x3527a6d3 0x32c6c891 0xb5a23 0x3b06cab7)
May  1 13:07:54 Download-WappZappTV ReportCrash[16066] <Notice>: ReportCrash acting against PID 16013
jonatansberg commented 10 years ago

@wienke I'm guessing this is an issue with the assets bundling and/or that the Mixpanel lib is searching for it's assets in the wrong bundle.

I don't have an environment capable of reproducing this at the moment though, so it's kind of hard so say anything more than that.

jonatansberg commented 10 years ago

@wienke Would you mind giving this a shot with v.0.3?

jonatansberg commented 10 years ago

These features are disabled for now, see #7.

jonatansberg commented 9 years ago

Status update: Swizzling the UIStoryboard loading to use another bundle is a possible solution. I gave that a quick shot last weekend, but unfortunately I was not able to get it working.

Just adding the storyboards to the assets (or Resources) folder did not work either, even though that should place them in the root of the final app bundle...

I will try to look in to this a bit further when I find the time.

inakiabt commented 9 years ago

:+1:

inakiabt commented 9 years ago

Hey @mrlundis! Any update on this?

inakiabt commented 9 years ago

Guys, I've been looking into it (I tried everything!) and I finally could receive in-app notifications. The bad news is that it's not a straightforward solution. Disclaimer: I'm not a Objective-C developer, I just know some basics things.

The solution steps are:

  1. Build the Titanium project with the TiMixpanel module included using ti build ...
  2. Open the generated Xcode project located in the "build/iphone" folder
  3. Add the Mixpanel SDK assets manually to the project copy-assets copy-bundle-resources
  4. Change the "Deployment Target" on "General" tab to "6.0" to resolve some errors with the storyboards autolayout (I don't know what I'm doing here) resolve-storyboard-error
  5. Run the project and voilà

To test it I've added a showNotification method on SeHyperlabMixpanelModule.m to call it from the test app:

// SeHyperlabMixpanelModule.m
- (void)showNotification:(id)args
{
    [[Mixpanel sharedInstance] showNotification];
}

app.js

...
button.addEventListener('click', function () {
  mixpanel.showNotification();
});

I've been doing some research on how to do all of these steps from the titanium build command. Adding the Mixpanel SDK assets to the "assets" folder or "platform/iphone" folder in TiMixpanel will be added to the example project when building but the storyboard seems like needs to be compiled or the app will crash. I came to this conclusion looking into the app contents after doing the above steps (look to the .storyboardc extension): app-contents

Do you know how to compile the storyboard on module or project build? What happen if we add my compiled storyboards to TiMixpanel assets for everyone who want to use the module?

jonatansberg commented 9 years ago

Great work @inakiabt! :smile:

I'm thinking about if there's some way we can get the normal titanium build process to do this for us..

Building a normal storyboard project in Xcode outputs something along these lines:

CompileStoryboard SBTest/Base.lproj/Main.storyboard
    cd /Users/jonatanlundin/Code/SBTest
    export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    export XCODE_DEVELOPER_USR_PATH=/Applications/Xcode.app/Contents/Developer/usr/bin/..
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ibtool --target-device iphone --target-device ipad --errors --warnings --notices --module SBTest --minimum-deployment-target 8.1 --output-partial-info-plist /Users/jonatanlundin/Library/Developer/Xcode/DerivedData/SBTest-hasnsyfilaskvtekpmzlrwbwxffh/Build/Intermediates/SBTest.build/Debug-iphonesimulator/SBTest.build/Main-SBPartialInfo.plist --auto-activate-custom-fonts --output-format human-readable-text --compile /Users/jonatanlundin/Library/Developer/Xcode/DerivedData/SBTest-hasnsyfilaskvtekpmzlrwbwxffh/Build/Products/Debug-iphonesimulator/SBTest.app/Base.lproj/Main.storyboardc /Users/jonatanlundin/Code/SBTest/SBTest/Base.lproj/Main.storyboard
inakiabt commented 9 years ago

@mrlundis that command is exactly what we need. I forked the project adding a script to compile the storyboards before build the module: https://github.com/inakiabt/TiMixpanel/blob/4a228de868976e920f10f5c6ba60ae80aac9d846/ios/compile-storyboards.sh

Would be great if you guys could test it in your environment, because it's working in my case but I can't assure it will work on any app.

Note: In my fork, I've re-enabled show surveys and notifications on active.

timanrebel commented 9 years ago

One possible solution might be to use a titanium cli plugin. My HockeyApp module uses a plugin to insert some code into the iOS build proces. Maybe that can be re-used and adapted? Afaik the plugin needs to be installed manually though.

https://github.com/timanrebel/HockeyApp/blob/master/iphone/plugin/hockeyapp/1.0/hooks/plugin.js

Or do we only have to compile them once? And then ship with the module? Only to recompile them when they change?

timanrebel commented 9 years ago

@inakiabt it is working here on iOS btw!

inakiabt commented 9 years ago

I guess the storyboards should be recompiled when they change, so storyboards compiled should be added to the module. I will start using this feature in our app soon (merging 0.7 with my fork). @mrlundis do you think adding the compiled storyboards is enough to realease a new version of the module?

jonatansberg commented 9 years ago

@inakiabt I'd love to see this in a new release! And if we can do this without the need for a cli plugin, that's even better :)

Would you be up to creating the new release as a pull request? Our release process is quite simple:

inakiabt commented 9 years ago

Done! :+1:

jonatansberg commented 9 years ago

Sweet! Let's continue the discussion over in #22.