0

呼び出されていない私は、すべて適切に名前が付けられ、彼らが提供されるこのファイルている拡張子を追加して、OneSignalのガイドを設定し、その後:自分で概説したようOneSignal(iOS版) - didReceiveNotificationRequest

#import <OneSignal/OneSignal.h> 

#import "NotificationService.h" 

@interface NotificationService() 

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver); 
@property (nonatomic, strong) UNNotificationRequest *receivedRequest; 
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent; 

@end 

@implementation NotificationService 

- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler { 


    self.receivedRequest = request; 
    self.contentHandler = contentHandler; 
    self.bestAttemptContent = [request.content mutableCopy]; 

    [OneSignal didReceiveNotificationExtensionRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent]; 

    self.contentHandler(self.bestAttemptContent); 
} 

- (void)serviceExtensionTimeWillExpire { 
    // Called just before the extension will be terminated by the system. 
    // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used. 

    [OneSignal serviceExtensionTimeWillExpireRequest:self.receivedRequest withMutableNotificationContent:self.bestAttemptContent]; 

    self.contentHandler(self.bestAttemptContent); 
} 
@end 

はまたAppDelegateのためのすべてのコードをコピーここでの設定ガイドは https://documentation.onesignal.com/docs/ios-sdk-setupと、githubでお勧めの人物として 'center'変数を作成するためのコードです。このインスタンスをAppDelegateに追加すると、didReceiveRemoteNotificationが呼び出されるようになりましたが、didReceiveNotificationExtensionRequestは呼び出されませんでした。

#import "AppDelegate.h" 

@interface AppDelegate() 
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) 
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) 
@end 

#import <OneSignal/OneSignal.h> 

@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

    // Replace '11111111-2222-3333-4444-ab' with your OneSignal App ID. 
    [OneSignal initWithLaunchOptions:launchOptions 
           appId:@"xxxxxxx (my app id is here)" 
      handleNotificationAction:nil 
          settings:@{kOSSettingsKeyAutoPrompt: @false}]; 
    OneSignal.inFocusDisplayType = OSNotificationDisplayTypeNotification; 

    // Recommend moving the below line to prompt for push after informing the user about 
    // how your app will use them. 
    [OneSignal promptForPushNotificationsWithUserResponse:^(BOOL accepted) { 
     NSLog(@"User accepted notifications: %d", accepted); 
    }]; 

    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; 
    center.delegate = self; 
    // Call syncHashedEmail anywhere in your iOS app if you have the user's email. 
    // This improves the effectiveness of OneSignal's "best-time" notification scheduling feature. 
    // [OneSignal syncHashedEmail:userEmail]; 

    return YES; 
} 

-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void 
                                   (^)(UIBackgroundFetchResult))completionHandler 
{ 
    // iOS 10 will handle notifications through other methods 

    if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")) 
    { 
     NSLog(@"iOS version >= 10. Let NotificationCenter handle this one."); 
     // set a member variable to tell the new delegate that this is background 

     //this block here gets called when I debug 

     return; 
    } 
    NSLog(@"HANDLE PUSH, didReceiveRemoteNotification: %@", userInfo); 

    // custom code to handle notification content 

    if([UIApplication sharedApplication].applicationState == UIApplicationStateInactive) 
    { 
     NSLog(@"INACTIVE"); 
     completionHandler(UIBackgroundFetchResultNewData); 
    } 
    else if([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) 
    { 
     NSLog(@"BACKGROUND"); 
     completionHandler(UIBackgroundFetchResultNewData); 
    } 
    else 
    { 
     NSLog(@"FOREGROUND"); 
     completionHandler(UIBackgroundFetchResultNewData); 
    } 
} 

@end 

私が必要とする「didReceiveNotificationExtensionRequest」私はiOSの10の可変コンテンツ機能を使用しようとしているからです。私はブレークポイントを入れて、didReceiveNotificationExtensionRequestが呼び出されないことを確信しています。私は.mファイルが何もしないので、クラスのどこかに接続する必要があるのだろうかと思います。それは私の携帯電話を問題にした場合すべてのヘルプは

を高く評価(2.5.4)IOS 10.0(そう変更可能なコンテンツをサポートする必要があります)とOneSignalバージョンをされ実行されているiOSの10 didReceiveRemoteNotification方法で おかげ

+0

同じものがここにありました。スウィフトでやろうとしました。拡張機能は呼び出されませんでした。 OneSignalフォーラムによれば、content-availableがtrueに設定されている場合、拡張機能は呼び出されません。私は、利用可能なオフ、変更可能なコンテンツをオンにしました。私は通知を受け取り、内容を変更することができました。構造は異なります。例:additionalDataは '' 'としてアクセスできます url =((userInfo [" custom "]?[[String:Any])?[" a "]?[[String:Any])?[" url " ]として?文字列 '' ' –

答えて

0

は呼び出されません。..あなたのために行く必要があります

- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
     willPresentNotification:(UNNotification *)notification 
     withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler 
関連する問題