简体   繁体   English

应用程式在装置上当机,但在Simulator上运作正常

[英]App crashes on device, however works fine on Simulator

My addressbook app works fine on Simulator. 我的通讯录应用程序在Simulator上运行良好。 I have Contact Add feature. 我有联系人添加功能。 On device(IOS 6) it get crashed.. with following message. 在设备(IOS 6)上,它崩溃了,并显示以下消息。

ContactPro[837] has active assertions beyond permitted time: 
{(
<BKProcessAssertion: 0x1f5a28a0> identifier: Suspending process: ContactPro[837] permittedBackgroundDuration: 10.000000 reason: suspend owner pid:52 preventSuspend         preventThrottleDownCPU  preventThrottleDownUI )}

After that, many lines of information comes like this 之后,许多信息便像这样

Elapsed total CPU time (seconds): 10.030 (user 10.030, system 0.000), 100% CPU 
Elapsed application CPU time (seconds): 3.724, 37% CPU

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0:
0   libsystem_c.dylib               0x33be8b1e __vfprintf + 158
1   libsystem_c.dylib               0x33b93106 vsnprintf_l + 170
2   libsystem_c.dylib               0x33b9455c snprintf + 68
3   libsystem_c.dylib               0x33b968a6 asl_string_append_char_no_encoding + 102
4   libsystem_c.dylib               0x33b9694c asl_string_append_internal + 124
5   libsystem_c.dylib               0x33b96536 asl_msg_to_string_raw + 118
6   libsystem_c.dylib               0x33b95b06 _asl_send_message + 1018
7   CoreFoundation                  0x380d417a __CFLogCString + 602
8   CoreFoundation                  0x3807801e _CFLogvEx + 186
9   Foundation                      0x3a13ed8a NSLogv + 82
10  Foundation                      0x3a13ed2a NSLog + 22
11  ContactPro                      0x000a7d38 0xa4000 + 15672
12  ContactPro                      0x000a686e 0xa4000 + 10350
13  ContactPro                      0x000b9dd0 0xa4000 + 89552
14  UIKit                           0x37a6f590 -[UIViewController loadViewIfRequired] +  360
15  UIKit                           0x37ac4136 -[UIViewController contentScrollView] + 22
16  UIKit                           0x37ac407c -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 24
17  UIKit                           0x37ac3f60 -[UINavigationController _layoutViewController:] + 28
18  UIKit                           0x37ac3e84 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 268
19  UIKit                           0x37ac35c4 -[UINavigationController _startTransition:fromViewController:toViewController:] + 60
20  UIKit                           0x37ac34ac -[UINavigationController _startDeferredTransitionIfNeeded:] + 320
21  UIKit                           0x37a944e4 -[UILayoutContainerView layoutSubviews] + 176
22  UIKit                           0x37a53806 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 254
23  QuartzCore                      0x36145d5e -[CALayer layoutSublayers] + 210
24  QuartzCore                      0x361458fc CA::Layer::layout_if_needed(CA::Transaction*) + 456
25  QuartzCore                      0x361747a2 -[CALayer layoutIfNeeded] + 138
26  UIKit                           0x37afd0cc -[UIViewController window:setupWithInterfaceOrientation:] + 204
27  UIKit                           0x37afc2b8 -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + 3616
28  UIKit                           0x37afb48a -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:] + 42
29  UIKit                           0x37afb414 -[UIWindow _setRotatableViewOrientation:duration:force:] + 64
30  UIKit                           0x37c3117c __57-[UIWindow _updateToInterfaceOrientation:duration:force:]_block_invoke_0 + 100
31  UIKit                           0x37ab967e -[UIWindow _updateToInterfaceOrientation:duration:force:] + 214
32  UIKit                           0x37ab93c0 -[UIWindow setAutorotates:forceUpdateInterfaceOrientation:] + 688
33  UIKit                           0x37ab8d2e -[UIViewController _tryBecomeRootViewControllerInWindow:] + 154
34  UIKit                           0x37aafea6 -[UIWindow addRootViewControllerViewIfPossible] + 366
35  UIKit                           0x37aabae8 -[UIWindow _setHidden:forced:] + 360
36  UIKit                           0x37aed1cc -[UIWindow makeKeyAndVisible] + 56
37  ContactPro                      0x000a5c88 0xa4000 + 7304
38  UIKit                           0x37ab0ad4 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 248
39  UIKit                           0x37ab065e -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1186
40  UIKit                           0x37aa8846 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 694
41  UIKit                           0x37a50c3c -[UIApplication handleEvent:withNewEvent:] + 1000
42  UIKit                           0x37a506d0 -[UIApplication sendEvent:] + 68
43  UIKit                           0x37a5011e _UIApplicationHandleEvent + 6150
44  GraphicsServices                0x35ce35a0 _PurpleEventCallback + 588
45  CoreFoundation                  0x380bb680 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
46  CoreFoundation                  0x380baee4 __CFRunLoopDoSources0 + 208
47  CoreFoundation                  0x380b9cb2 __CFRunLoopRun + 642
48  CoreFoundation                  0x3802ceb8 CFRunLoopRunSpecific + 352
49  CoreFoundation                  0x3802cd44 CFRunLoopRunInMode + 100
50  UIKit                           0x37aa7480 -[UIApplication _run] + 664
51  UIKit                           0x37aa42fc UIApplicationMain + 1116
52  ContactPro                      0x000a5864 0xa4000 + 6244
53  libdyld.dylib                   0x36982b1c start + 0

Can anyone provide some tips as to how to solve it! 任何人都可以提供一些解决方法的提示!

For accessing ADDRESS BOOK in IOS6, i am using following lines.. ABAddressBookRef ab = ABAddressBookCreateWithOptions(NULL, NULL); 为了在IOS6中访问ADDRESS BOOK,我使用了以下几行。ABAddressBookRef ab = ABAddressBookCreateWithOptions(NULL,NULL);

__block BOOL accessGranted = NO;
if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
    dispatch_semaphore_t sema = dispatch_semaphore_create(0);
    ABAddressBookRequestAccessWithCompletion(ab, ^(bool granted, CFErrorRef error) {
        accessGranted = granted;
        dispatch_semaphore_signal(sema);
    });
    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
    //        dispatch_release(sema);
}
else { // we're on iOS 5 or older
    accessGranted = YES;
}

if (accessGranted) {
    // Do whatever you want here
}

I changed the Addressbook access code, 我更改了地址簿访问码,

ABAddressBookRef abcd = ABAddressBookCreateWithOptions(NULL, NULL);
__block BOOL accessGranted = NO;
    if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusNotDetermined) {
    ABAddressBookRequestAccessWithCompletion(abcd, ^(bool granted, CFErrorRef error) {
        // First time access has been granted, add the contact
        accessGranted = granted;
    });
}
else if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusAuthorized) {
    // The user has previously given access, add the contact
    accessGranted = YES;
}
else {
    // The user has previously denied access
    // Send an alert telling user to change privacy setting in settings app
}

if (accessGranted) {
    CFIndex recordsCount = ABAddressBookGetPersonCount(abcd);
    CFArrayRef all = ABAddressBookCopyArrayOfAllPeople(abcd);
    ABRecordRef ref = CFArrayGetValueAtIndex(all,recordsCount);
    NSLog(@"%@", ref);
    ABRecordID record = ABRecordGetRecordID(ref);
}                                                                                              

With this also i am not getting a reference to Contact?.. Also the app getting crashed in both Simulator and Device. 与此同时,我也没有获得对Contact?的引用。.该应用程序在Simulator和Device中都崩溃了。 However i am getting access to AddressBook. 但是我正在访问AddressBook。 #pls suggest me.. what can be done to solve this issue. #pls建议我..如何解决此问题。 Thanks 谢谢

Thanks & Regards 感谢和问候

I think the problem is this: you are using a semaphore to block the thread until "the green light" appears. 我认为问题是这样的:您正在使用信号量来阻止线程,直到出现“绿灯”为止。 But you are executing this code on the thread 0 (the main thread, that manages the user interface). 但是,您正在线程0(管理用户界面的主线程)上执行此代码。 For this reason you are blocking all changes in the user interface, including the alert requesting access to contacts. 因此,您将阻止用户界面中的所有更改,包括请求访问联系人的警报。

EDIT for the new code First thing: try on a device. 编辑新代码首先:在设备上尝试。 For some reason, Simulator always return authorized even if not: ABAddressBookGetAuthorizationStatus in simulator always returns kABAuthorizationStatusAuthorized . 出于某种原因,模拟器即使未授权也始终返回授权: 模拟器中的ABAddressBookGetAuthorizationStatus始终返回kABAuthorizationStatusAuthorized

Second thing, your "if (accessGranted)" won't be executed the first time the user authorize the app, because it is executed before the completion block (the completion block waits the user decision), but the code immediately after the block is executed immediately. 第二件事,您的“ if(accessGranted)”不会在用户第一次授权应用程序时执行,因为它是完成块之前执行的(完成块等待用户决定),但是紧随该块之后的代码是立即执行。 You should move that code in another function (called after the completion block only once authorized, for example). 您应该将该代码移动到另一个函数中(例如,仅在获得授权后在完成块之后调用)。 But, for testing purpose, this code should work the second time you try to access the AB, once authorized. 但是,出于测试目的,一旦获得授权,该代码应在您第二次尝试访问AB时起作用。

Your accessGranted code is fine except one thing: if you have an array of 250 records, you are trying to access the record 250 (that doesn't exists, the last record is number 249). 您可以使用accessGranted代码,但有以下几点:如果您有250条记录的数组,则您正在尝试访问250条记录(该记录不存在,最后一条记录为249号)。 Change this line 更改此行

ABRecordRef ref = CFArrayGetValueAtIndex(all,recordsCount);

with this 有了这个

ABRecordRef ref = CFArrayGetValueAtIndex(all,recordsCount-1);

I tried and it works 我尝试了并且有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序在模拟器上崩溃,但升级到狮子后在设备上运行正常 - App crashes on simulator but works fine in device after upgrading to lion Xamarin应用程序在设备启动时崩溃,在模拟器中运行良好 - Xamarin app crashes on startup on device, works fine in simulator 应用程序在模拟器上正常运行,但在设备上崩溃 - Application works fine on the simulator but crashes on the device MPMoviePlayer在设备中崩溃,但在模拟器中工作正常 - MPMoviePlayer crashes in device but works fine in simulator 应用程序在模拟器上工作正常但在设备上崩溃 - application works fine on simulator but crashes on device 使用XCode进行调试时,应用可以正常运行,在设备或模拟器上运行时,应用会崩溃 - When debugging with XCode, app works fine, when running it on device or simulator, app crashes 在设备上启动app的例外,在模拟器中工作正常 - Exception on app startup in device,works fine in simulator 应用在模拟器上崩溃。 适用于iPhone设备 - App crashes on simulator. Works on iphone device iPhone应用程序由于内存不足而崩溃,但在模拟器中可以正常使用 - iPhone App Crashes due to Low Memory but works fine in simulator 应用程序在iPhone / iPod上运行良好,但在iPad(甚至模拟器)上崩溃 - App works fine on iPhone/ iPod but crashes on iPad (even simulator)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM