0

I have trouble with WCSession activateSession. I added this code in my viewDidLoad method, and it's crashing at activateSession call. sendMessage is also crashing.

if ([WCSession isSupported]) {
    [WCSession defaultSession].delegate = self;
    [[WCSession defaultSession] activateSession];
}

I though that problem my be with thread, but I debug it and these calls on main thread.

any idea what can be the problem?

here is crash log:

thread #1: tid = 0x10aa81, 0x0000000110917817 libobjc.A.dylibobjc_msgSend + 23, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x408f59958d3) frame #0: 0x0000000110917817 libobjc.A.dylibobjc_msgSend + 23 frame #1: 0x000000010be8fd1c myApp+[CRWCSessionDelegateProxy performSwizzledWCSessionActivateSession:] + 62 frame #2: 0x000000010be8f869 myApp+[CRWCSessionDelegateProxy activateSessionForWCSession:dispatch:] + 72 frame #3: 0x000000010be8ec64 myApp__72+[CRWCSessionDelegateProxy swizzleWCSessionActivateSessionWithDispatch:]_block_invoke + 37 * frame #4: 0x000000010bd6c4e4 myApp-[FPMAppDelegate application:didFinishLaunchingWithOptions:](self=0x00007ff588d06800, _cmd="application:didFinishLaunchingWithOptions:", application=0x00007ff588c00850, launchOptions=0x0000000000000000) + 5236 at FPMAppDelegate.m:188 frame #5: 0x000000010e50d1f1 UIKit-[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 272 frame #6: 0x000000010e50e397 UIKit-[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3415 frame #7: 0x000000010e514cc6 UIKit-[UIApplication _runWithMainScene:transitionContext:completion:] + 1760 frame #8: 0x000000010e511e7b UIKit-[UIApplication workspaceDidEndTransaction:] + 188 frame #9: 0x0000000113203754 FrontBoardServices-[FBSSerialQueue _performNext] + 192 frame #10: 0x0000000113203ac2 FrontBoardServices-[FBSSerialQueue _performNextFromRunLoopSource] + 45 frame #11: 0x0000000110db4a31 CoreFoundation__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 frame #12: 0x0000000110daa95c CoreFoundation__CFRunLoopDoSources0 + 556 frame #13: 0x0000000110da9e13 CoreFoundation__CFRunLoopRun + 867 frame #14: 0x0000000110da9828 CoreFoundationCFRunLoopRunSpecific + 488 frame #15: 0x000000010e5117cd UIKit-[UIApplication _run] + 402 frame #16: 0x000000010e516610 UIKitUIApplicationMain + 171 frame #17: 0x000000010bcdc8cf myAppmain(argc=1, argv=0x00007fff540ca3c0) + 111 at main.m:16 frame #18: 0x0000000111ab292d libdyld.dylibstart + 1

toxicsun
  • 397
  • 3
  • 12
  • Share the console log. your code is fine. – Muneeba Jan 08 '16 at 10:38
  • Is there any other piece of code in your AppDelegate 's didfinishlaunchoption method? – Muneeba Jan 08 '16 at 10:49
  • yes, there is bunch of code. but i think problem is with session.delegate. i have move this code to init and viewdidload, and the same crash happens – toxicsun Jan 08 '16 at 10:51
  • The above code is fine.You are targeting watche os 2 , you have implemented all the required things. Did you run your app with above code commented out ? – Muneeba Jan 08 '16 at 10:54
  • this is happens when i'm runing ios app. on watchkit it works fine. – toxicsun Jan 08 '16 at 10:55
  • I never encounter this issue in my app. neither if i run my target iOS app only. Can u share ur code.? – Muneeba Jan 08 '16 at 11:02
  • The call stack method names (such as `performSwizzledWCSessionActivateSession`) makes it sound like you are doing some swizzling; my guess is something is going wrong there. What is the goal with the swizzling you are doing? – ccjensen Jan 08 '16 at 14:38
  • I'm not doing swizzling in my project. I think this is can be thread problem, i created new project and copy past the WCSession code and it works fine. what is strange to me is the session.delegate (see in this link: http://imgur.com/AfDmDZv) any idea what is CRWCSessionDelegateProxy? – toxicsun Jan 08 '16 at 14:58

2 Answers2

3

I have Crittercism framwork in my app. Once i commented this line in my app delegate method all works fine.

[Crittercism enableWithAppID:CRITTERCISM_APP_ID];

If you are using Cirttercism in your app, make sure to write this line [[WCSession defaultSession] activateSession] before Crittercism. Seems they have watch 2.0 support and that's the cause of conflict.

toxicsun
  • 397
  • 3
  • 12
1

Your code must be called before

[Crittercism enableWithAppID:].
Bws Sluk
  • 478
  • 5
  • 11