StoreKit SKProducts请求崩溃
我使用以下代码根据应用内购买编程指南请求产品列表。它曾经在我的 iPhone 应用程序中运行良好,但现在每次请求产品列表时都会崩溃。永远不会调用委托方法 (void)productsRequest:(SKProductsRequest **)request didReceiveResponse:(SKProductsResponse **)response
。
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"my.product.identifier"]];
[request setDelegate:self];
[request start];
正如我所说,它工作得很好,然后就停止工作了。这是调用上述代码时发生的崩溃。
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000011
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x000034f8 objc_msgSend + 24
1 StoreKit 0x00003e18 -[SKProductsRequest handleFinishResponse:returningError:] + 40
2 StoreKit 0x000050c4 -[SKRequest _requestFinishedNotification:] + 152
3 Foundation 0x00019b9a _nsnote_callback + 150
4 CoreFoundation 0x0006c2de __CFXNotificationPost_old + 390
5 CoreFoundation 0x0001ab32 _CFXNotificationPostNotification + 122
6 Foundation 0x000048e4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 64
7 AppSupport 0x0000bb42 -[CPDistributedNotificationCenter deliverNotification:userInfo:] + 38
8 AppSupport 0x0000cf66 _CPDNDeliverNotification + 198
9 AppSupport 0x0000ba4a _XDeliverNotification + 110
10 AppSupport 0x00002e82 migHelperRecievePortCallout + 122
11 CoreFoundation 0x000742ac __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 22
12 CoreFoundation 0x000761d6 __CFRunLoopDoSource1 + 158
13 CoreFoundation 0x0007718e __CFRunLoopRun + 574
14 CoreFoundation 0x0001e0bc CFRunLoopRunSpecific + 220
15 CoreFoundation 0x0001dfca CFRunLoopRunInMode + 54
16 GraphicsServices 0x00003f88 GSEventRunModal + 188
17 UIKit 0x00007b40 -[UIApplication _run] + 564
18 UIKit 0x00005fb8 UIApplicationMain + 964
19 myapp 0x00002fae main (main.m:13)
20 myapp 0x00002f58 start + 32
Thread 1:
0 libSystem.B.dylib 0x00034e84 kevent + 24
1 libSystem.B.dylib 0x00102a48 _dispatch_mgr_invoke + 88
2 libSystem.B.dylib 0x00102494 _dispatch_queue_invoke + 96
3 libSystem.B.dylib 0x00102634 _dispatch_worker_thread2 + 120
4 libSystem.B.dylib 0x0008b53c _pthread_wqthread + 392
5 libSystem.B.dylib 0x00082b6c start_wqthread + 0
Thread 2:
0 libSystem.B.dylib 0x00000ab0 mach_msg_trap + 20
1 libSystem.B.dylib 0x00002f94 mach_msg + 60
2 CoreFoundation 0x00074b18 __CFRunLoopServiceMachPort + 88
3 CoreFoundation 0x000770e0 __CFRunLoopRun + 400
4 CoreFoundation 0x0001e0bc CFRunLoopRunSpecific + 220
5 CoreFoundation 0x0001dfca CFRunLoopRunInMode + 54
6 WebCore 0x0000370c RunWebThread(void*) + 552
7 libSystem.B.dylib 0x0008af80 _pthread_start + 364
8 libSystem.B.dylib 0x0007d014 thread_start + 0
Thread 3:
0 libSystem.B.dylib 0x00000ab0 mach_msg_trap + 20
1 libSystem.B.dylib 0x00002f94 mach_msg + 60
2 CoreFoundation 0x00074b18 __CFRunLoopServiceMachPort + 88
3 CoreFoundation 0x000770e0 __CFRunLoopRun + 400
4 CoreFoundation 0x0001e0bc CFRunLoopRunSpecific + 220
5 CoreFoundation 0x0001dfca CFRunLoopRunInMode + 54
6 Foundation 0x0003c316 +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] + 210
7 Foundation 0x0000c612 -[NSThread main] + 42
8 Foundation 0x00092140 __NSThread__main__ + 908
9 libSystem.B.dylib 0x0008af80 _pthread_start + 364
10 libSystem.B.dylib 0x0007d014 thread_start + 0
Thread 4:
0 libSystem.B.dylib 0x00029f24 select$DARWIN_EXTSN + 20
1 CoreFoundation 0x0007aa54 __CFSocketManager + 340
2 libSystem.B.dylib 0x0008af80 _pthread_start + 364
3 libSystem.B.dylib 0x0007d014 thread_start + 0
我不知道是什么原因导致 objc_msgSend 崩溃,也不知道它与 StoreKit 有什么关系。我也不知道我添加或更改了什么导致这个简单的代码停止工作。
I use the following code to request a list of products as per the In-App Purchase Programming Guide. It used to work fine in my iPhone application, however now it crashes every time the product list is requested. The delegate method (void)productsRequest:(SKProductsRequest **)request didReceiveResponse:(SKProductsResponse **)response
is never called.
SKProductsRequest *request = [[SKProductsRequest alloc] initWithProductIdentifiers:[NSSet setWithObject:@"my.product.identifier"]];
[request setDelegate:self];
[request start];
As I said, it worked perfectly fine, then just stopped working. This is the crash which occurs when the above code is called.
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000011
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x000034f8 objc_msgSend + 24
1 StoreKit 0x00003e18 -[SKProductsRequest handleFinishResponse:returningError:] + 40
2 StoreKit 0x000050c4 -[SKRequest _requestFinishedNotification:] + 152
3 Foundation 0x00019b9a _nsnote_callback + 150
4 CoreFoundation 0x0006c2de __CFXNotificationPost_old + 390
5 CoreFoundation 0x0001ab32 _CFXNotificationPostNotification + 122
6 Foundation 0x000048e4 -[NSNotificationCenter postNotificationName:object:userInfo:] + 64
7 AppSupport 0x0000bb42 -[CPDistributedNotificationCenter deliverNotification:userInfo:] + 38
8 AppSupport 0x0000cf66 _CPDNDeliverNotification + 198
9 AppSupport 0x0000ba4a _XDeliverNotification + 110
10 AppSupport 0x00002e82 migHelperRecievePortCallout + 122
11 CoreFoundation 0x000742ac __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 22
12 CoreFoundation 0x000761d6 __CFRunLoopDoSource1 + 158
13 CoreFoundation 0x0007718e __CFRunLoopRun + 574
14 CoreFoundation 0x0001e0bc CFRunLoopRunSpecific + 220
15 CoreFoundation 0x0001dfca CFRunLoopRunInMode + 54
16 GraphicsServices 0x00003f88 GSEventRunModal + 188
17 UIKit 0x00007b40 -[UIApplication _run] + 564
18 UIKit 0x00005fb8 UIApplicationMain + 964
19 myapp 0x00002fae main (main.m:13)
20 myapp 0x00002f58 start + 32
Thread 1:
0 libSystem.B.dylib 0x00034e84 kevent + 24
1 libSystem.B.dylib 0x00102a48 _dispatch_mgr_invoke + 88
2 libSystem.B.dylib 0x00102494 _dispatch_queue_invoke + 96
3 libSystem.B.dylib 0x00102634 _dispatch_worker_thread2 + 120
4 libSystem.B.dylib 0x0008b53c _pthread_wqthread + 392
5 libSystem.B.dylib 0x00082b6c start_wqthread + 0
Thread 2:
0 libSystem.B.dylib 0x00000ab0 mach_msg_trap + 20
1 libSystem.B.dylib 0x00002f94 mach_msg + 60
2 CoreFoundation 0x00074b18 __CFRunLoopServiceMachPort + 88
3 CoreFoundation 0x000770e0 __CFRunLoopRun + 400
4 CoreFoundation 0x0001e0bc CFRunLoopRunSpecific + 220
5 CoreFoundation 0x0001dfca CFRunLoopRunInMode + 54
6 WebCore 0x0000370c RunWebThread(void*) + 552
7 libSystem.B.dylib 0x0008af80 _pthread_start + 364
8 libSystem.B.dylib 0x0007d014 thread_start + 0
Thread 3:
0 libSystem.B.dylib 0x00000ab0 mach_msg_trap + 20
1 libSystem.B.dylib 0x00002f94 mach_msg + 60
2 CoreFoundation 0x00074b18 __CFRunLoopServiceMachPort + 88
3 CoreFoundation 0x000770e0 __CFRunLoopRun + 400
4 CoreFoundation 0x0001e0bc CFRunLoopRunSpecific + 220
5 CoreFoundation 0x0001dfca CFRunLoopRunInMode + 54
6 Foundation 0x0003c316 +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] + 210
7 Foundation 0x0000c612 -[NSThread main] + 42
8 Foundation 0x00092140 __NSThread__main__ + 908
9 libSystem.B.dylib 0x0008af80 _pthread_start + 364
10 libSystem.B.dylib 0x0007d014 thread_start + 0
Thread 4:
0 libSystem.B.dylib 0x00029f24 select$DARWIN_EXTSN + 20
1 CoreFoundation 0x0007aa54 __CFSocketManager + 340
2 libSystem.B.dylib 0x0008af80 _pthread_start + 364
3 libSystem.B.dylib 0x0007d014 thread_start + 0
I don't know what is causing the objc_msgSend crash, or how it is related to StoreKit. I also have no idea what I added or changed which caused this simple code to stop working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一个很可能的解释是您设置为 SKProductRequest 对象委托的对象是否可能已被释放。
请求很可能需要几秒钟才能完成,并且这可能超出了委托对象的生命周期,因此您可能需要确保它保留足够长的时间。
A very likely explanation is whether the object you set as a delegate for the SKProductRequest object might have been deallocated already.
It is quite possible for the request to take a few seconds to complete, and this might be past the lifetime of your delegate object, so you may want to make sure it sticks around for long enough.
上面的答案在技术上是正确的,但并不完整。正如 Megastep 所说,“您设置为 SKProductsRequest 委托的对象可能已经被释放。”因此,您正在向已释放的对象发送消息。现在来看看实际的答案:
基本上,正如您在上面看到的,您不需要释放 productsRequest,因为它已经在委托回调方法中释放了。同样,您不需要调用 productsRequest release 或在 viewDidUnload/dealloc 方法中将其设置为 Nil,因为如果您在调用回调方法之前关闭视图,可能会导致崩溃。
The answer above is technically correct but it is not complete. As Megastep said "the object you set as the delegate for the SKProductsRequest may have already been deallocated." Therefore you are sending a message to an object that has already been deallocated. Now onto the actual answer:
So basically as you can see above you do not need to release productsRequest because it is already being released in the delegate callback method. Again you do not need to call productsRequest release or set it Nil in viewDidUnload/dealloc method because that could cause a crash if you dismiss the view before the callback method gets called.
我正在使用像委托这样的对象。因此,在该对象的 deinit 方法中,我删除了委托 a 并且崩溃已得到修复。
I'm using an object like a delegate. So in the deinit method of this object i remove the delegate a and crash has been fixed.