1

私のアドレス帳アプリはシミュレーターで正常に動作します。連絡先追加機能があります。デバイス(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 )}

その後、多くの情報がこのようになります

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

誰かがそれを解決する方法についていくつかのヒントを提供できますか?

IOS6でADDRESSBOOKにアクセスするには、次の行を使用しています。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
}

名簿のアクセスコードを変更しました。

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);
}                                                                                              

これでも連絡先への参照を取得していませんか?..また、アプリがシミュレータとデバイスの両方でクラッシュします。しかし、私はAddressBookにアクセスできます。#plsは私を提案します..この問題を解決するために何ができるか。ありがとう

ありがとうございます。それでは、お元気で

4

1 に答える 1

1

問題はこれだと思います。「緑色の光」が現れるまで、セマフォを使用してスレッドをブロックしています。ただし、このコードはスレッド 0 (ユーザー インターフェイスを管理するメイン スレッド) で実行しています。このため、連絡先へのアクセスを要求するアラートを含め、ユーザー インターフェースのすべての変更をブロックしています。

新しいコードの編集 まず、デバイスで試してください。何らかの理由で、シミュレーターは、そうでない場合でも常に承認済みを返します。シミュレーターの ABAddressBookGetAuthorizationStatus は、常に kABAuthorizationStatusAuthorized を返します

第二に、「if (accessGranted)」は、完了ブロックのに実行されるため (完了ブロックはユーザーの決定を待機します)、ユーザーが初めてアプリを承認したときに実行されませんが、ブロックの直後のコードはすぐに実行されます。そのコードを別の関数に移動する必要があります (たとえば、承認された場合にのみ完了ブロックの後に呼び出されます)。ただし、テストの目的で、このコードは、承認された後、AB に 2 回アクセスしようとしたときに機能するはずです。

あなたの accessGranted コードは 1 つのことを除いて問題ありません: 250 レコードの配列がある場合、レコード 250 にアクセスしようとしています (それは存在しません。最後のレコードは 249 番です)。この行を変更

ABRecordRef ref = CFArrayGetValueAtIndex(all,recordsCount);

これとともに

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

私は試してみましたが、うまくいきます

于 2012-10-31T07:40:38.680 に答える