0

ExtensionDelegate를 내 UNUserNotificationCenterDelegate로 만들고 올바르게 할당했습니다.watchOS 3 - userNotificationCenter에서해야 할 일은 무엇입니까? willPresentNotification : withCompletionHandler : 실제로 알림을 표시 하시겠습니까?

- (void) userNotificationCenter:(UNUserNotificationCenter*)center 
     willPresentNotification:(UNNotification*)notification 
      withCompletionHandler:(void(^)(UNNotificationPresentationOptions))completionHandler 
{ 
    NSLog(@"ExtensionDelegate: willPresent!"); 

    completionHandler(UNNotificationPresentationOptionAlert); 
} 

문제는 아무 변화가 없다는 것입니다 : 내 watchOS 3 응용 프로그램은 다음과 같이 내가 방법을 구현 한

userNotificationCenter:willPresentNotification:withCompletionHandler: 

트리거 알림 요청을 추가 할 수 있습니다. 내가 watchOS 3.1을 실행하는 장치에서 Xcode 8.2에서 디버깅 중이며이 위임 메서드가 트리거되었지만 중단 점에 도달 할 수 있지만 경고가 표시되지 않습니다.

UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init]; 
    content.title = notificationType; 
    content.subtitle = [NSString stringWithFormat:@"Subtitle: %@", notificationType]; 
    content.body = alertTitle; 
    content.badge = @1; 
    content.sound = [UNNotificationSound defaultSound]; 
    content.launchImageName = @"LaunchImage"; 
    content.userInfo = @{ 
         @"notificationType" : notificationType, 
         @"count" : @(count) 
         }; 
    content.attachments = @[]; 
    content.categoryIdentifier = notificationType; 

notificationType 다음과 같이 내 응용 프로그램의 실행에 설정된는 NSString입니다 : 불행하게도

// Register custom notification types 
    UNNotificationCategory* cat1 = [UNNotificationCategory categoryWithIdentifier:@"Category1" 
                      actions:@[dismissAction] 
                   intentIdentifiers:@[] 
                      options:UNNotificationCategoryOptionNone]; 

    UNNotificationCategory* cat2 = [UNNotificationCategory categoryWithIdentifier:@"Category2" 
                      actions:@[dismissAction, yesAction] 
                    intentIdentifiers:@[] 
                      options:UNNotificationCategoryOptionNone]; 
    NSSet* categorySet = [NSSet setWithArray:@[cat1, cat2]]; 
    [center setNotificationCategories:categorySet]; 

알림 요청이있을 때, willPresentNotification이 왕래의 completionHandler를 다음과 같이 내 컨텐츠입니다 호출되고, 그 다음 앱은 포 그라운드에서 계속 실행됩니다. 화면에 알림 경고가 표시되지 않습니다. 시계 모드의 드래그 다운 도크에는 나타나지 않습니다. 화면 상에 또는 그곳에 또는 풀다운 선창에 나타나게하려면 무엇을해야합니까?

다음은 앱 상단에서 볼 수있는 화면의 예입니다. 또는 화면 상단에서 플러시 상단으로 이동하고 그 아래에서 앱이 실행됩니다.

Simple watchOS Notification

+0

알림을 보낼 권한을 요청 했습니까? 시계 프로그래밍 가이드 : 시스템에서 알림을 게시하거나 앱 알림을위한 사운드를 재생하기 전에 Watch 앱 또는 iOS 앱이 사용자와 상호 작용할 수있는 권한을 요청해야합니다. 공유 UNUserNotificationCenter 오브젝트의 requestAuthorizationWithOptions : completionHandler : 메소드를 호출하여이를 수행하십시오. – lostAtSeaJoshua

+0

아니요, 시작시 권한을 요청하고 시작시 가져 왔습니다. 나는 단지 실제적인 경고 그 자체를 보낼 필요가있다. 표시되는 시계 화면 상단의 배너와 마찬가지로 사라집니다. WKInterfaceView (또는 무엇이든)로 만들어야합니까? – Cindeselia

+0

내게 불분명 한 점은 위임자의 willPresentNotification이 호출 될 때 실제로 알림을 표시하기 위해 무엇을해야 하는가? UI를 변경하는 것과 같은 화려한 사용자 정의 동작은 필요 없습니다. 시계 아이콘 상단에있는 작은 아이콘 (일부 디자이너는 '팬케이크'또는 '축배'라고 함)을 앱 아이콘과 한 줄의 텍스트. "목표 달성!" 또는 무엇이든. 이것은 예를 들어 시계면의 스 와이프 다운 메뉴에서 볼 수있는 알림 유형입니다. 나는 그것을 보여줄 필요가있다. 처음부터 코드를 작성해야합니까? 우리가 무료로 얻을 수없는 것 같아. – Cindeselia

답변

0

관련 질문,하지만 iOS 용 : 여기에 표시된 것보다 배너도 얇은 될 수 나는 시계에 같은 일을 시도하고 같은 (비 표시 알림을 받게 된 Displaying a stock iOS notification banner when your app is open and in the foreground?

) 결과. 하나의 노트는 다른 사람들을 돕는 경우 완성 핸들러에서 반환하는 것과 동일한 허가를 요청해야한다는 것입니다. 예를 들어, Alert 알림을 표시하려면 아래에 표시된 두 가지 값을 사용해야합니다. OP가 언급했듯이, 우리는 노 티피 케이션 센터 델리게이트로 스스로를 설정해야합니다.

(여기에 오류가있는 경우 BTW에서 지적 했으므로 아직 작동하지 않습니다.)

다음 코드는 Watchkit Extension 대리인에 있습니다.

- (void)applicationDidFinishLaunching { 
    // ... 
    // Register for, and request permission to send notifications 
    UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter]; 
    center.delegate = self; 
    [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert) 
         completionHandler:^(BOOL granted, NSError * _Nullable error) { 
          // Enable or disable features based on authorization. 
          NSLog(@"Got auth response: %d", granted); 
         }]; 
} 

알림 권한이 "iPhone 미러링"으로 설정된 경우에만 위 작업이 성공합니다. 이 기능을 끄면 권한 요청이 실패합니다. 다른 문제가 있지만 반품 된 granted 값을 확인하고 true인지 확인하십시오.

// Foreground notification 
- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
     willPresentNotification:(UNNotification *)notification 
      withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler { 
    // The method will be called on the delegate only if the 
    // application is in the foreground. 
    NSLog(@"Will present notification: %@", notification); 
    // The following doesn't present the notification, though. 
    completionHandler(UNNotificationPresentationOptionAlert); 
} 

userNotificationCenter:willPresentNotification:withCompletionHandler 방법

은 전화를받을 않습니다,하지만 난 통지 오버레이가 표시되지 않으며 알림 목록에 하나가있다.