I study iOS Programming alone and I want make Youtube app.
I want that I can listen when I clicked home button and I want listen many song(like a youtube playlist. but not a list I can chose song in my tablelist.)
I use youtube-ios-player-libarary https://github.com/youtube/youtube-ios-player-helper and I solved if I press home button app continous play in background.
But I have problem now.
When I listen in background youtube video sound and than video ended don't play next video. In the app is working, but not in background. I don't get any log in Xcode like this. (I tried Zombie)

I tried to work in main thread, like this:
[self performSelectorOnMainThread:@selector(createNewWebView) withObject:nil waitUntilDone:YES];
and
  dispatch_async(dispatch_get_main_queue(), ^{
        [self.webView removeFromSuperview];
       _webView = [self createNewWebView];
       [self addSubview:self.webView];
    });
But it didn't work, and now I found this device log:
Date/Time:           2016-01-18 15:42:46.46 +0900
Launch Time:         2016-01-18 15:42:33.33 +0900
OS Version:          iOS 9.2 (13C75)
Report Version:      105
Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x00000001
Triggered by Thread:  13
Thread 13 name:  WebThread
Thread 13 Crashed:
0   libGPUSupportMercury.dylib      0x31e3d322 gpus_ReturnNotPermittedKillClient + 10
1   libGPUSupportMercury.dylib      0x31e3de12 gpusSubmitDataBuffers + 118
2   IMGSGX543RC2GLDriver            0x34bd968c 0x34bd6000 + 13964
3   WebCore                         0x29260792 WebCore::GraphicsContext3D::reshape(int, int) + 434
4   WebCore                         0x299371e2 WebCore::WebGLRenderingContextBase::initializeNewContext() + 502
5   WebCore                         0x29936dd0 WebCore::WebGLRenderingContextBase::WebGLRenderingContextBase(WebCore::HTMLCanvasElement*, WTF::PassRefPtr<WebCore::GraphicsContext3D>, WebCore::GraphicsContext3D::Attributes) + 484
6   WebCore                         0x29931be0 WebCore::WebGLRenderingContext::WebGLRenderingContext(WebCore::HTMLCanvasElement*, WTF::PassRefPtr<WebCore::GraphicsContext3D>, WebCore::GraphicsContext3D::Attributes) + 48
7   WebCore                         0x29936720 WebCore::WebGLRenderingContextBase::create(WebCore::HTMLCanvasElement*, WebCore::WebGLContextAttributes*, WTF::String const&) + 772
8   WebCore                         0x28fcfbca WebCore::HTMLCanvasElement::getContext(WTF::String const&, WebCore::CanvasContextAttributes*) + 250
9   WebCore                         0x28fcfa46 WebCore::JSHTMLCanvasElement::getContext(JSC::ExecState*) + 154
10  WebCore                         0x28fcf988 WebCore::jsHTMLCanvasElementPrototypeFunctionGetContext(JSC::ExecState*) + 88
11  JavaScriptCore                  0x28bad71e llint_entry + 21374
12  JavaScriptCore                  0x28bad338 llint_entry + 20376
13  JavaScriptCore                  0x28bad338 llint_entry + 20376
14  JavaScriptCore                  0x28bad338 llint_entry + 20376
15  JavaScriptCore                  0x28bad338 llint_entry + 20376
16  JavaScriptCore                  0x28ba8190 vmEntryToJavaScript + 336
17  JavaScriptCore                  0x28b016da JSC::JITCode::execute(JSC::VM*, JSC::ProtoCallFrame*) + 102
18  JavaScriptCore                  0x288eaa18 JSC::Interpreter::executeCall(JSC::ExecState*, JSC::JSObject*, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) + 344
19  JavaScriptCore                  0x288ea8bc JSC::call(JSC::ExecState*, JSC::JSValue, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) + 60
20  JavaScriptCore                  0x2897d780 JSC::boundFunctionCall(JSC::ExecState*) + 324
21  JavaScriptCore                  0x28bad71e llint_entry + 21374
22  JavaScriptCore                  0x28bad4ba llint_entry + 20762
23  JavaScriptCore                  0x28bad338 llint_entry + 20376
24  JavaScriptCore                  0x28bad338 llint_entry + 20376
25  JavaScriptCore                  0x28ba8190 vmEntryToJavaScript + 336
26  JavaScriptCore                  0x28b016da JSC::JITCode::execute(JSC::VM*, JSC::ProtoCallFrame*) + 102
27  JavaScriptCore                  0x288eaa18 JSC::Interpreter::executeCall(JSC::ExecState*, JSC::JSObject*, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) + 344
28  JavaScriptCore                  0x288ea8bc JSC::call(JSC::ExecState*, JSC::JSValue, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) + 60
29  JavaScriptCore                  0x2897d780 JSC::boundFunctionCall(JSC::ExecState*) + 324
30  JavaScriptCore                  0x28bad71e llint_entry + 21374
31  JavaScriptCore                  0x28bad338 llint_entry + 20376
32  JavaScriptCore                  0x28ba8190 vmEntryToJavaScript + 336
33  JavaScriptCore                  0x28b016da JSC::JITCode::execute(JSC::VM*, JSC::ProtoCallFrame*) + 102
34  JavaScriptCore                  0x288eaa18 JSC::Interpreter::executeCall(JSC::ExecState*, JSC::JSObject*, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) + 344
35  JavaScriptCore                  0x288ea8bc JSC::call(JSC::ExecState*, JSC::JSValue, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) + 60
36  JavaScriptCore                  0x2897d780 JSC::boundFunctionCall(JSC::ExecState*) + 324`enter code here`
37  JavaScriptCore                  0x28bad71e llint_entry + 21374
38  JavaScriptCore                  0x28bad338 llint_entry + 20376
39  JavaScriptCore                  0x28ba8190 vmEntryToJavaScript + 336
40  JavaScriptCore                  0x28b016da JSC::JITCode::execute(JSC::VM*, JSC::ProtoCallFrame*) + 102
41  JavaScriptCore                  0x288eaa18 JSC::Interpreter::executeCall(JSC::ExecState*, JSC::JSObject*, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) + 344
42  JavaScriptCore                  0x289c6f38 JSC::call(JSC::ExecState*, JSC::JSValue, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&, WTF::NakedPtr<JSC::Exception>&) + 64
43  WebCore                         0x28f95df2 WebCore::JSEventListener::handleEvent(WebCore::ScriptExecutionContext*, WebCore::Event*) + 490
44  WebCore                         0x291e17d8 WebCore::EventTarget::fireEventListeners(WebCore::Event*, WebCore::EventTargetData*, WTF::Vector<WebCore::RegisteredEventListener, 1ul, WTF::CrashOnOverflow, 16ul>&) + 532
45  WebCore                         0x28edb96c WebCore::EventTarget::fireEventListeners(WebCore::Event*) + 232
46  WebCore                         0x28fd60a0 WebCore::EventTarget::dispatchEvent(WTF::PassRefPtr<WebCore::Event>) + 64
47  WebCore                         0x291aebe6 WebCore::DOMWindow::dispatchMessageEventWithOriginCheck(WebCore::SecurityOrigin*, WTF::PassRefPtr<WebCore::Event>, WTF::PassRefPtr<Inspector::ScriptCallStack>) + 66
48  WebCore                         0x291aeb62 WebCore::DOMWindow::postMessageTimerFired(WebCore::PostMessageTimer&) + 98
49  WebCore                         0x291b212e WebCore::PostMessageTimer::fired() + 14
50  WebCore                         0x28e89898 WebCore::ThreadTimers::sharedTimerFiredInternal() + 136
51  WebCore                         0x28e897ec WebCore::timerFired(__CFRunLoopTimer*, void*) + 28
52  CoreFoundation                  0x25b919e6 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 14
53  CoreFoundation                  0x25b91618 __CFRunLoopDoTimer + 936
54  CoreFoundation                  0x25b8f464 __CFRunLoopRun + 1500
55  CoreFoundation                  0x25ae1bb8 CFRunLoopRunSpecific + 516
56  CoreFoundation                  0x25ae19ac CFRunLoopRunInMode + 108
57  WebCore                         0x28ecfcbe RunWebThread(void*) + 422
58  libsystem_pthread.dylib         0x25906c7e _pthread_body + 138
59  libsystem_pthread.dylib         0x25906bf2 _pthread_start + 110
60  libsystem_pthread.dylib         0x25904a08 thread_start + 8
———————————— 16.01.19 tried
dispatch_async(dispatch_get_main_queue(), ^{
   if (self.webView != nil) {
      self.webView removeFromSuperview];
      _webView = [self createNewWebView];
      [self addSubview:self.webView];
   }
});
and
if (self.webView == nil) {
      self.webView removeFromSuperview];
      _webView = [self createNewWebView];
      [self addSubview:self.webView];
   }
but It didn’t work.
What can I change or add code ? Please help me guys..
Its crashing because of open GL in the background. You will need to disable open GL if the app is in background. Here is the Code to do that :
typedef void (*CallFuc)(id, SEL, BOOL);
typedef BOOL (*GetFuc)(id, SEL);
-(BOOL)webView:(UIWebView*)view enableGL:(BOOL)bEnable
{
BOOL bRet = NO;
do
{
    Ivar internalVar = class_getInstanceVariable([view class], "_internal");
    if (!internalVar)
    {
        NSLog(@"enable GL _internal invalid!");
        break;
    }
    UIWebViewInternal* internalObj = object_getIvar(view, internalVar);
    Ivar browserVar = class_getInstanceVariable(object_getClass(internalObj), "browserView");
    if (!browserVar)
    {
        NSLog(@"enable GL browserView invalid!");
        break;
    }
    id webbrowser = object_getIvar(internalObj, browserVar);
    Ivar webViewVar = class_getInstanceVariable(object_getClass(webbrowser), "_webView");
    if (!webViewVar)
    {
        NSLog(@"enable GL _webView invalid!");
        break;
    }
    id webView = object_getIvar(webbrowser, webViewVar);
    if (!webView)
    {
        NSLog(@"enable GL webView obj nil!");
    }
    if(object_getClass(webView) != NSClassFromString(@"WebView"))
    {
        NSLog(@"enable GL webView not WebView!");
        break;
    }
    SEL selector = NSSelectorFromString(@"_setWebGLEnabled:");
    IMP impSet = [webView methodForSelector:selector];
    CallFuc func = (CallFuc)impSet;
    func(webView, selector, bEnable);
    SEL selectorGet = NSSelectorFromString(@"_webGLEnabled");
    IMP impGet = [webView methodForSelector:selectorGet];
    GetFuc funcGet = (GetFuc)impGet;
    BOOL val = funcGet(webView, selector);
    bRet = (val == bEnable);
}while(NO);
return bRet;
}
Call [self webView:self.yourWebView enableGL:NO] when app is in background.
 Saqibdb
 SaqibdbUser contributions licensed under CC BY-SA 3.0