2014-06-22 4 views
0

동일한 앱을 가진 다른 기기의 사용자가 기기에 연결하려고하는지 사용자에게 알리는 앱을 실험하고 있습니다. 앱에 수신 비컨을 설정하고 표시 할 앱 위임자에게 전송되는 위치 관리자 알림을 설정합니다. 알림을받는 사람이 확인 버튼을 탭하면 작업을 수행하려고합니다. 여기 내 코드 중 일부입니다.비콘에서 appDelegate 알림에 응답

는 BeaconViewController

의 수신기 비콘
NSUUID * uid2 = [[NSUUID alloc] initWithUUIDString:@"3B257014-2C29-40E0-8E1E-1D7A9E5D0964"]; 
     self.beaconRegion2 = [[CLBeaconRegion alloc] initWithProximityUUID:uid2 identifier:@"com.checkers.bluetooth"]; 
     [self.beaconRegion2 setNotifyEntryStateOnDisplay:YES]; 
     [self.beaconRegion2 setNotifyOnEntry:YES]; 
     [self.beaconRegion2 setNotifyOnExit:YES]; 

// 응용 프로그램 위임

-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { 

    // See if we've entered the region. 
    if ([region.identifier isEqualToString:@"com.checkers.bluetooth"]) { 
     UILocalNotification * notification = [[UILocalNotification alloc] init]; 
     notification.alertBody = @"Want to play checkers?"; 

     [[UIApplication sharedApplication] presentLocalNotificationNow:notification]; 
    } 
} 

에 통지를 보내을 설정 // AppDelegate에 내가 알림을 설정 //

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.locationManager = [[CLLocationManager alloc]init]; 
    self.locationManager.delegate= self; 
    // Override point for customization after application launch. 
    return YES; 
} 

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { 
    AlertView= [[UIAlertView alloc] initWithTitle:@"Play a Game?" 
                message:notification.alertBody 
               delegate:NULL 
             cancelButtonTitle:@"OK" 
             otherButtonTitles:@"CANCEL", nil]; 
    [AlertView show]; 

     if ([notification.alertBody isEqualToString:@"Want to play Chess?"]) { 
      messageString = @"chess"; 
      NSLog(@"messageSting:%@",messageString); 
     }} 

// "OK"버튼을 눌렀는지 확인하려고합니다.

-(void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{ 

    if (buttonIndex == 0) { 
    if ([messageString isEqualToString:@"chess"]) { 
     messageString3 = @"Play Chess"; 
    } 
    } 
    } 

는 // 마지막으로 BeaconViewController에 나는 이것의 결과는 그래서 내가 통지를 받기 뷰 컨트롤러

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
     messageString2 = appDelegate.messageString3; 
     NSLog(@"messageSting2:%@",messageString2); 

에서 작업을 만들 수 있습니다 넘겨 싶어 내가 통지를 인식 할 수 있습니다. alertBody하지만 어떤 버튼이 탭되고 있는지 알 수 없으며 알림의 버튼을 탭하여 messageString3에 값을 할당 할 수 없습니다.

누군가 도와 드릴 수 있습니까?

답변

0

그래서 이것을 알아 냈습니다. 두 가지 이유 1. UIAlertView를 만들고 합성하여 원하는대로 참조 할 수있었습니다. 2. alertView를 보면 delegate가 NULL로 설정되어 있고 self로 설정되어야합니다.

한 번이 두 가지를 모두 수행하면 모든 것이 효과적입니다.