mardi 5 avril 2016

Unrecognized selector sent to instance - Objective C

I tried to make an Mac OS application. I try to do a web browser in a popover. I used WKWebView. When I call an URL, I have this message in the console :

2016-04-05 21:14:35.827 Popup[3125:385906] -[WebView loadRequest:]: unrecognized selector sent to instance 0x600000120820
2016-04-05 21:14:35.827 Popup[3125:385906] -[WebView loadRequest:]: unrecognized selector sent to instance 0x600000120820
2016-04-05 21:14:35.829 Popup[3125:385906] (
    0   CoreFoundation                      0x00007fff8c1ef4f2 __exceptionPreprocess + 178
    1   libobjc.A.dylib                     0x00007fff8fd66f7e objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff8c2591ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x00007fff8c15f571 ___forwarding___ + 1009
    4   CoreFoundation                      0x00007fff8c15f0f8 _CF_forwarding_prep_0 + 120
    5   Popup                               0x0000000100004aa6 -[PanelController goWhatsApp:] + 182
    6   libsystem_trace.dylib               0x00007fff8d92907a _os_activity_initiate + 75
    7   AppKit                              0x00007fff95695e89 -[NSApplication sendAction:to:from:] + 460
    8   AppKit                              0x00007fff956a7fde -[NSControl sendAction:to:] + 86
    9   AppKit                              0x00007fff956a7f08 __26-[NSCell _sendActionFrom:]_block_invoke + 131
    10  libsystem_trace.dylib               0x00007fff8d92907a _os_activity_initiate + 75
    11  AppKit                              0x00007fff956a7e65 -[NSCell _sendActionFrom:] + 144
    12  libsystem_trace.dylib               0x00007fff8d92907a _os_activity_initiate + 75
    13  AppKit                              0x00007fff956a648a -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2693
    14  AppKit                              0x00007fff956eefd0 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 744
    15  AppKit                              0x00007fff956a4bb4 -[NSControl mouseDown:] + 669
    16  AppKit                              0x00007fff95bf9469 -[NSWindow _handleMouseDownEvent:isDelayedEvent:] + 6322
    17  AppKit                              0x00007fff95bfa44d -[NSWindow _reallySendEvent:isDelayedEvent:] + 212
    18  AppKit                              0x00007fff9563963d -[NSWindow sendEvent:] + 517
    19  AppKit                              0x00007fff955b9b3c -[NSApplication sendEvent:] + 2540
    20  AppKit                              0x00007fff95420ef6 -[NSApplication run] + 796
    21  AppKit                              0x00007fff953ea46c NSApplicationMain + 1176
    22  Popup                               0x0000000100000fe2 main + 34
    23  libdyld.dylib                       0x00007fff90e925ad start + 1
    24  ???                                 0x0000000000000003 0x0 + 3
)

I have searched on Google since 3 days but I don't find a answer which works for me.

This is my code : In PanelController.h

#import "BackgroundView.h"
#import "StatusItemView.h"
#import <Webkit/Webkit.h>
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>

@import WebKit;

@class PanelController;

@protocol PanelControllerDelegate <NSObject>

@optional

- (StatusItemView *)statusItemViewForPanelController:(PanelController *)controller;

@end

#pragma mark -

@interface PanelController : NSWindowController <NSWindowDelegate>
{
    BOOL _hasActivePanel;
    __strong IBOutlet WKWebView *_webView;
    __unsafe_unretained IBOutlet NSButton *_btnWhatsApp;
    __unsafe_unretained IBOutlet NSButton *_btnMessenger;
    __unsafe_unretained BackgroundView *_backgroundView;
    __unsafe_unretained id<PanelControllerDelegate> _delegate;
    __unsafe_unretained NSSearchField *_searchField;
    __unsafe_unretained NSTextField *_textField;
}

@property (nonatomic, unsafe_unretained) IBOutlet BackgroundView *backgroundView;
@property (nonatomic, unsafe_unretained) IBOutlet NSSearchField *searchField;
@property (nonatomic, unsafe_unretained) IBOutlet NSTextField *textField;
@property (unsafe_unretained) IBOutlet NSButton *btnMessenger;
@property (unsafe_unretained) IBOutlet NSButton *btnWhatsApp;
@property (strong, nonatomic) IBOutlet WKWebView *webView;

@property (nonatomic) BOOL hasActivePanel;
@property (nonatomic, unsafe_unretained, readonly) id<PanelControllerDelegate> delegate;

- (id)initWithDelegate:(id<PanelControllerDelegate>)delegate;

- (void)openPanel;
- (void)closePanel;

@end

In PanelController.m

#import "PanelController.h"
#import "BackgroundView.h"
#import "StatusItemView.h"
#import "MenubarController.h"
@import WebKit;

@implementation PanelController

@synthesize backgroundView = _backgroundView;
@synthesize delegate = _delegate;
@synthesize searchField = _searchField;
@synthesize textField = _textField;
@synthesize webView = _webView;
.
.
.
.
.
- (IBAction)goGoogle:(id)sender {
    NSString* useragent = @"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/601.5.17 (KHTML, like Gecko) Version/9.1 Safari/601.5.17";
    [_webView setCustomUserAgent:useragent];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]];
    [_webView loadRequest:urlRequest];
}

Thanks for your answers !




Aucun commentaire:

Enregistrer un commentaire