Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何将UnuseNotificationCenter和AppDelegate设置为FlotterStreamHandler事件接收器_Ios_Objective C_Flutter_Apple Push Notifications - Fatal编程技术网

Ios 如何将UnuseNotificationCenter和AppDelegate设置为FlotterStreamHandler事件接收器

Ios 如何将UnuseNotificationCenter和AppDelegate设置为FlotterStreamHandler事件接收器,ios,objective-c,flutter,apple-push-notifications,Ios,Objective C,Flutter,Apple Push Notifications,我想在iOS中使用与apns相关的功能的FlightStreamHandler。TokenStreamHandler和MessageStreamHandler将接收设备令牌和用户信息反馈给dart端,但我遇到了如何将AppDelegate和UnuseNotificationCenter委托事件接收器添加到特定流处理程序的问题 b.h #import <Flutter/Flutter.h> @interface FlutterPushPlugin : NSObject <Flu

我想在iOS中使用与apns相关的功能的FlightStreamHandler。TokenStreamHandler和MessageStreamHandler将接收设备令牌和用户信息反馈给dart端,但我遇到了如何将AppDelegate和UnuseNotificationCenter委托事件接收器添加到特定流处理程序的问题

b.h

#import <Flutter/Flutter.h>

@interface FlutterPushPlugin : NSObject <FlutterPlugin>
@end

@interface TokenStreamHandler : NSObject <FlutterStreamHandler>
@end

@interface MessageStreamHandler : NSObject <FlutterStreamHandler>
@end
#导入
@接口插件:NSObject
@结束
@接口TokenStreamHandler:NSObject
@结束
@接口MessageStreamHandler:NSObject
@结束
是的

#import "FlutterPushPlugin.h"
#import <UserNotifications/UserNotifications.h>

@implementation FlutterPushPlugin {
  ...
}

#pragma mark - FlutterPlugin

+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  
  // Init plugin...
  
  FlutterEventChannel* tokenEventChannel =
      [FlutterEventChannel eventChannelWithName:@"flutter_push/token"
                                binaryMessenger:[registrar messenger]];
  TokenStreamHandler* tokenStreamHandler = [[TokenStreamHandler alloc] init];
  [tokenEventChannel setStreamHandler:tokenStreamHandler];
  
  FlutterEventChannel* messageEventChannel =
      [FlutterEventChannel eventChannelWithName:@"flutter_push/message"
                            binaryMessenger:[registrar messenger]];
  MessageStreamHandler* messageStreamHandler = [[MessageStreamHandler alloc] init];
  [messageEventChannel setStreamHandler:messageStreamHandler];
  
  // ...
}

#pragma mark - UNUserNotificationCenter Delegate Methods

// Receive displayed notifications for iOS 10 devices.
// Handle incoming notification messages while app is in the foreground.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
    API_AVAILABLE(macos(10.14), ios(10.0)) {
  NSDictionary *userInfo = notification.request.content.userInfo;
  
  // 2. Get the UserInfo when app on foreground.
  
  completionHandler(UNNotificationPresentationOptionBadge | UNNotificationPresentationOptionAlert);

}

// Handle notification messages after display notification is tapped by the user.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
    didReceiveNotificationResponse:(UNNotificationResponse *)response
             withCompletionHandler:(void (^)(void))completionHandler
    API_AVAILABLE(macos(10.14), ios(10.0)) {
  NSDictionary *userInfo = response.notification.request.content.userInfo;
  
  // 2. Get the UserInfo when app on background.

  completionHandler();
}

#pragma mark - AppDelegate Methods

- (void)application:(UIApplication *)application
    didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  const char *data = [deviceToken bytes];
  NSMutableString *ret = [NSMutableString string];
  for (NSUInteger i = 0; i < [deviceToken length]; i++) {
    [ret appendFormat:@"%02.2hhx", data[i]];
  }
  
  // 1. Get the device token.
}

@end

#pragma mark - TokenStreamHandler impl

@implementation TokenStreamHandler {
  FlutterEventSink _eventSink;
}

- (FlutterError*)onListenWithArguments:(id)arguments eventSink:(FlutterEventSink)events {
  _eventSink = events;
  
  // 1. How to set AppDelegate Delegate to TokenStreamHandler event sink for getting the token?
  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(onTokenDidChange:)
                                               name:UIDeviceTokenDidChangeNotification
                                             object:nil];
  return nil;
}

- (FlutterError*)onCancelWithArguments:(id)arguments {
  return nil;
}

@end

#pragma mark - MessageStreamHandler impl

@implementation MessageStreamHandler {
  FlutterEventSink _eventSink;
}

- (FlutterError*)onCancelWithArguments:(id)arguments {
  _eventSink = events;

  // 2. How to set UNUserNotificationCenter Delegate to MessageStreamHandler event sink for getting the UserInfo?
  [[NSNotificationCenter defaultCenter] addObserver:self
                                           selector:@selector(onMessageDidChange:)
                                               name:UIMessageDidChangeNotification
                                             object:nil];
  return nil;
}

- (FlutterError*)onListenWithArguments:(id)arguments eventSink:(FlutterEventSink)events {
  return nil;
}

@end
#导入“flatterpushplugin.h”
#进口
@插件的实现{
...
}
#pragma-mark-plugin
+(无效)注册人和注册人:(NSObject*)注册人{
//初始化插件。。。
FlatterEventChannel*令牌事件频道=
[FlatterEventChannel eventChannelWithName:@“Flatter_推送/令牌”
binaryMessenger:[注册信使]];
TokenStreamHandler*TokenStreamHandler=[[TokenStreamHandler alloc]init];
[tokenEventChannel setStreamHandler:tokenStreamHandler];
FlatterEventChannel*消息事件频道=
[FlatterEventChannel eventChannelWithName:@“Flatter\u推送/消息”
binaryMessenger:[注册信使]];
MessageStreamHandler*MessageStreamHandler=[[MessageStreamHandler alloc]init];
[messageEventChannel setStreamHandler:messageStreamHandler];
// ...
}
#pragma标记-未使用通知中心委托方法
//接收iOS 10设备的显示通知。
//在应用程序处于前台时处理传入的通知消息。
-(void)用户通知中心:(UNUserNotificationCenter*)中心
遗嘱提示通知:(未通知*)通知
withCompletionHandler:(void(^)(UNNotificationPresentationOptions选项))completionHandler
API_可用(macos(10.14)、ios(10.0)){
NSDictionary*userInfo=notification.request.content.userInfo;
//2.应用程序在前台时获取用户信息。
完成处理程序(未通知PresentationOptionBadge |未通知PresentationOptionErt);
}
//在用户点击显示通知后处理通知消息。
-(void)用户通知中心:(UNUserNotificationCenter*)中心
didReceiveNotificationResponse:(未通知响应*)响应
withCompletionHandler:(void(^)(void))completionHandler
API_可用(macos(10.14)、ios(10.0)){
NSDictionary*userInfo=response.notification.request.content.userInfo;
//2.应用程序在后台运行时获取用户信息。
completionHandler();
}
#pragma标记-AppDelegate方法
-(无效)申请:(UIApplication*)申请
DidRegisterForRemotonificationswithDeviceToken:(NSData*)deviceToken{
常量字符*数据=[deviceToken字节];
NSMutableString*ret=[NSMutableString];
对于(整数i=0;i<[deviceToken length];i++){
[ret appendFormat:@“%02.2hhx”,数据[i]];
}
//1.获取设备令牌。
}
@结束
#pragma标记-TokenStreamHandler impl
@实现令牌流处理器{
FlatterEventSink _eventSink;
}
-(FlatterError*)仅包含以下参数的ListenWithArguments:(id)arguments eventSink:(FlatterEventSink)events{
_eventSink=事件;
//1.如何将AppDelegate委托设置为TokenStreamHandler事件接收器以获取令牌?
[[NSNotificationCenter defaultCenter]添加观察者:self
选择器:@selector(onTokenDidChange:)
名称:UIDeviceTokenDicChangeNotification
对象:无];
返回零;
}
-(错误*)onCancelWithArguments:(id)参数{
返回零;
}
@结束
#pragma标记-MessageStreamHandler impl
@实现MessageStreamHandler{
FlatterEventSink _eventSink;
}
-(错误*)onCancelWithArguments:(id)参数{
_eventSink=事件;
//2.如何将UNUserNotificationCenter委托设置为MessageStreamHandler事件接收器以获取用户信息?
[[NSNotificationCenter defaultCenter]添加观察者:self
选择器:@selector(onMessageDidChange:)
名称:UIMessageDidChangeNotification
对象:无];
返回零;
}
-(FlatterError*)仅包含以下参数的ListenWithArguments:(id)arguments eventSink:(FlatterEventSink)events{
返回零;
}
@结束