OneSignal通知中的按钮操作?

如何获取通知警报操作事件处理程序?

  • 在AppDelegate.m中

    [OneSignal initWithLaunchOptions:launchOptions appId:@“把应用ID放在这里。” handleNotificationReceived:^(OSNotification * notification){NSLog(@“Received Notification - %@”,notification.payload.notificationID); } handleNotificationAction:^(OSNotificationOpenedResult *结果){

        // This block gets called when the user reacts to a notification received
        OSNotificationPayload* payload = result.notification.payload;
    
        NSString* messageTitle = @"OneSignal Example";
        NSString* fullMessage = [payload.body copy];
    
        if (payload.additionalData) {
    
            if(payload.title)
                messageTitle = payload.title;
    
            if (result.action.actionID)
                fullMessage = [fullMessage stringByAppendingString:[NSString stringWithFormat:@"nPressed ButtonId:%@", result.action.actionID]];
        }
    } settings:@{kOSSettingsKeyInFocusDisplayOption : @(OSNotificationDisplayTypeNotification), kOSSettingsKeyAutoPrompt : @YES}];
    
    [OneSignal IdsAvailable:^(NSString *userId, NSString *pushToken) {
        if(pushToken) {
            NSLog(@"Received push token - %@", pushToken);
            NSLog(@"User ID - %@", userId);
        }
       }];
    
  • (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@“http://www.google.com”]]; }
  • 链接地址: http://www.djcxy.com/p/67265.html

    上一篇: button action from OneSignal notification?

    下一篇: Swift remote push notifications with GCM