2015-02-25 4 views
0

проблемаподключения Multipeer - Реклама ViewController и браузер ViewController

мне удалось получить эту работу после урока и может успешно передавать данные между устройствами. Тем не менее, я сейчас пытаюсь реализовать это в своем приложении.

Проблема в том, что она не рекламирует в моем HostViewController.

Возможно, мне не хватает чего-то невероятно легкого, однако я не могу найти проблему.

HostViewController ~ Рекламодатель.

#import "HostViewController.h" 
#import "AppDelegate.h" 
@interface HostViewController() 

@property (nonatomic,strong) AppDelegate *appDelegate; 

@end 

@implementation HostViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    [_matchName setDelegate:self]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (IBAction)createMatchup:(id)sender { 

    _appDelegate.mcManager.peerID = nil; 
    _appDelegate.mcManager.session = nil; 
    _appDelegate.mcManager.browser = nil; 
    _appDelegate.mcManager.advertiser = nil; 

    [_appDelegate.mcManager.advertiser stop]; 

    [_appDelegate.mcManager setupPeerAndSessionWithDisplayName:_matchName.text]; 
    [_appDelegate.mcManager setupMCBrowser]; 
    [_appDelegate.mcManager advertiseSelf:true]; 
} 

-(BOOL)textFieldShouldReturn:(UITextField *)textField{ 
    [_matchName resignFirstResponder]; 

    return YES; 
} 
@end 

ConnectionViewController ~ ведет к браузеру.

#import "ConnectionsViewController.h" 
#import "AppDelegate.h" 
#import "LobbyViewController.h" 

@interface ConnectionsViewController() 

@property (nonatomic, strong) AppDelegate *appDelegate; 

@end 

@implementation ConnectionsViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    _appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
    [[_appDelegate mcManager] setupPeerAndSessionWithDisplayName:[UIDevice currentDevice].name]; 
    [[_appDelegate mcManager] advertiseSelf:false]; 
} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (IBAction)browseForDevices:(id)sender { 
    [[_appDelegate mcManager] setupMCBrowser]; 
    [[[_appDelegate mcManager] browser] setDelegate:self]; 
    [self presentViewController:[[_appDelegate mcManager] browser] animated:YES completion:nil]; 
} 

-(void)browserViewControllerDidFinish:(MCBrowserViewController *)browserViewController{ 
    [_appDelegate.mcManager.browser dismissViewControllerAnimated:NO completion:nil]; 
    //Here go to match lobby. 
    LobbyViewController *lobby = [[LobbyViewController alloc] init]; 
    [self presentViewController:lobby animated:YES completion:nil]; 
} 


-(void)browserViewControllerWasCancelled:(MCBrowserViewController *)browserViewController{ 
    [_appDelegate.mcManager.browser dismissViewControllerAnimated:YES completion:nil]; 
} 
@end 

И, наконец,;

MCManager ~ обрабатывает события

@implementation MCManager 

-(id)init{ 
    self = [super init]; 

    if (self) { 
     _peerID = nil; 
     _session = nil; 
     _browser = nil; 
     _advertiser = nil; 
    } 

    return self; 
} 

-(void)setupPeerAndSessionWithDisplayName:(NSString *)displayName{ 
    _peerID = [[MCPeerID alloc] initWithDisplayName:displayName]; 

    _session = [[MCSession alloc] initWithPeer:_peerID]; 
    _session.delegate = self; 
} 

-(void)setupMCBrowser{ 
    _browser = [[MCBrowserViewController alloc] initWithServiceType:@"chat-files" session:_session]; 
} 

-(void)advertiseSelf:(BOOL)shouldAdvertise{ 
    if (shouldAdvertise) { 
     _advertiser = [[MCAdvertiserAssistant alloc] initWithServiceType:@"chat-files" 
                  discoveryInfo:nil 
                   session:_session]; 
     [_advertiser start]; 
    } 
    else{ 
     [_advertiser stop]; 
     _advertiser = nil; 
    } 
} 

-(void)session:(MCSession *)session peer:(MCPeerID *)peerID didChangeState:(MCSessionState)state{ 

} 


-(void)session:(MCSession *)session didReceiveData:(NSData *)data fromPeer:(MCPeerID *)peerID{ 

} 


-(void)session:(MCSession *)session didStartReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID withProgress:(NSProgress *)progress{ 

} 


-(void)session:(MCSession *)session didFinishReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID atURL:(NSURL *)localURL withError:(NSError *)error{ 

} 


-(void)session:(MCSession *)session didReceiveStream:(NSInputStream *)stream withName:(NSString *)streamName fromPeer:(MCPeerID *)peerID{ 

} 

@end 

Хост ViewController является @interface HostViewController : UIViewController <MCAdvertiserAssistantDelegate,UITextFieldDelegate>

соединения ViewControiller является @interface ConnectionsViewController : UIViewController <MCBrowserViewControllerDelegate>

Тем не менее, я не могу видеть имя устройства/Matchup после -(IBAction)createMatchup:(id)sender уже побежал.

Резюме

Имя/матчап устройство не отображается для просмотра устройства после того, как createMatchup уже побежал.

ответ

0
- (void)viewDidLoad { 
.... 
    _appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 

в viewdidload из HostViewController.

Знал, что это было что-то маленькое = [