2012-11-23 4 views
4

로컬 UILocalNotification을 만들고 배너로 사용자에게 표시하고 있습니다. 사용자가 앱을 탭하여 앱으로 돌아 왔을 때 앱이 특정 종류의 알림에 대한 데이터를 수신하도록 설정할 수 있습니까? 앱에서 특정보기 컨트롤러를 열려고합니다. 나는 최선의 방법은 본질적으로 애플 리케이션에 URL을 보낼 것이라고 생각하거나 어떤 종류가 있었는지 테스트 할 수 있도록 오른쪽 동작을 UILocalNotification에 액세스 할 수있는 방법이 무엇입니까?UILocalNotification의 사용자 탭 : 데이터를 앱에 전달할 수 있습니까?

+1

: 예를 들어 "하지만 덕분에 나는 IOS에 특별히 관심이 nsusernotificationdelegate는 OS X에서만입니다."- 질문 완전히 잘못된 및 잘못된 것입니다. 편집 됨 –

답변

1

UST는이 방법을 NSUserNotificationCenterDelegate를 구현하고 정의

- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification 

예 :

이 나는 ​​"알리미"응용 프로그램에서했던 것입니다.

- (void) userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification 
{ 
NSRunAlertPanel([notification title], [notification informativeText], @"Ok", nil, nil); 
} 

- (void) userNotificationCenter:(NSUserNotificationCenter *)center didDeliverNotification:(NSUserNotification *)notification 
{ 
notifications=nil; 
[tableView reloadData]; 
[center removeDeliveredNotification: notification]; 
} 

알림이 활성화되면 나는 즉시 전달 알림을 제거이 경우 .IN 난 그냥 (내가 HUD 창을 사용할 수 있습니다) 패널을 사용자에게 통보 (사용자가 클릭),하지만이없는 것입니다 통보는 언젠가 거기 체재 할 수 있고 1/2 시간 후에 제거 될 수있다 (당신이 개발하고있는 신청에 달려있다).

+0

OS X 10.8에서만 사용 가능합니다. iOS에서도 비슷한 기능이 있습니까? – Jason

6

iOS 앱으로 전달되는 로컬 NSUserNotification에서 데이터를 가져 오려면 다음 방법을 구현해야합니다. - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification.

문제는 앱이 백그라운드에있을 때 (즉, 사용자가 알림을 탭한 다음 앱으로 돌아갈 때) 로컬 알림이 게시 될 때와 앱이 로컬 알림이 실행될 때 포어 그라운드 (타이머가 설정되어 있음). 앱이 배경이나 전경에있을 때 알림이 시작되면 어떻게 알아 내야하나요? 꽤 간단합니다. 당신이있는 NSDictionary를 보유하고 notification.userInfo에 따라 통지를 처리 ​​할 수있는이 시점에서

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { 
    UIApplicationState state = [application applicationState]; 
    if (state == UIApplicationStateInactive) { 
     // Application was in the background when notification was delivered. 
    } else { 
     // App was running in the foreground. Perhaps 
     // show a UIAlertView to ask them what they want to do? 
    } 
} 

: 여기에 내 코드입니다.

+0

nvm, 그저 아래에있는 주석은 그가 원하는 것을 말합니다. –

0

1 - NSUserNoficationCenterDelegate 프로토콜을 구현하는 프로젝트에서 어떤 클래스를 정의

@interface someObject : NSObject <NSUserNotificationCenterDelegate> 
{ 
- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification; 
} 

2 (here를 문서화) - 기본 알림 센터의 대리인으로 개체 정의 # 1의 인스턴스를 설정합니다.

[[NSUserNotificationCenter defaultNotificationCenter] setDelegate: someObject]; 

사용자가 알림을 탭하거나 클릭 할 때마다 didActivateNotification이 호출됩니다. 작성한 원래 통보가 있습니다. 따라서 필요한 모든 정보를 사용할 수 있어야합니다.

알림 제목, 메시지 등 특별한 정보가 필요하거나 필요하면 알림을 보내도록 예약하기 전에 알림에 추가 응용 프로그램 정보를 설정해야 할 수 있습니다. 아래 댓글에서

NSUserNotification* notification = [[NSUserNotification alloc] init]; 
NSDictionary* specialInformation = [NSDictionary dictionaryWithObjectsAndKeys: @"specialValue", @"specialKey", nil]; 
[notification setUserInfo:specialInformation]; 
+0

고마워요.하지만 저는 특히 이오스에 관심이 있어요.nsusernotificationdelegate는 OS X에만 있습니다. – Jason

+2

그러면 잘못된 클래스에 대해 묻고 있습니다. NSUserNotification은 OSX 클래스입니다. iOS에 로컬 알림을 보내려는 경우 NSUserNotification이 아닌 UILocalNotification에 대해 묻고 있어야합니다. iPhone 클래스는 일반적으로 "UI"로 시작하고 OSX 클래스는 일반적으로 "NS"로 시작합니다. –

관련 문제