遠(yuǎn)程flutter,遠(yuǎn)程查看別人微信聊天記錄

flutter 遠(yuǎn)程推送

如果要在殺掉app情況下收到推送,需要在不同的手機(jī)渠道商處注冊(cè)

創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都做網(wǎng)站、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的天涯網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

Flutter中使用gRPC

gRPC是谷歌開(kāi)發(fā)的一款遠(yuǎn)程過(guò)程調(diào)用系統(tǒng),可以讓客戶端像調(diào)用本地對(duì)象一樣使用服務(wù)端應(yīng)用的方法,使用protocol buffers接口定義語(yǔ)言來(lái)定義服務(wù)方法,protocol buffer定義參數(shù)和返回類型。

protobuf類似json,是一種數(shù)據(jù)結(jié)構(gòu)協(xié)議,在android studio中安裝Protobuf Support,方便查看編寫的proto文件

dart使用proto插件將proto文件生成對(duì)應(yīng)的dart文件,使用如下步驟

1、安裝flutter之后,再flutter的下面路徑中有pub命令,需要將命令加入到path中。

可以vi ~/.zshrc,在文件中加入source ~/.bash_profile,然后在vi ~/.bash_profile文件中加入下面路徑(:分割不同的路徑)

export PATH=/Users/webull/app/flutter/bin:/Users/webull/app/flutter/bin/cache/dart-sdk/bin:/Users/webull/.pub-cache/bin:$PATH

其中fluter/bin是flutter的命令路徑,dart-sdk/bin中包含了pub和其他dart命令,.pub-cache/bin是之后運(yùn)行pub之后建立的路徑,里面包含了proto-gen-dart命令,用來(lái)將proto文件轉(zhuǎn)換為dart的命令

2、使用下面的命令安裝proto插件

$ pub global activate protoc_plugin

安裝完成后,上面的用戶目錄中的.pub-cache目錄才會(huì)有proto-gen-dart文件。

1、其中/Users/webull是我的用戶目錄 app/flutter是flutter的安裝目錄

參考:

1、gRPC介紹

2、gRPC配置

Flutter注冊(cè)iOS推送

####總結(jié):

Flutter在iOS中AppDelegate繼承自FlutterAppDelegate,所以很多方法必須重寫父類中的方法。iOS的推送注冊(cè)流程還是一樣的。不一樣的是需要給推送設(shè)置別名或者將設(shè)備的deviceToken上傳到推送服務(wù)器,這一步可以原生實(shí)現(xiàn)也可以flutter實(shí)現(xiàn),但是還是需要和flutter進(jìn)行交互,這是就需要注冊(cè)一個(gè)通道實(shí)現(xiàn)這個(gè)。通道也可以增加別的一些例如:信息處理等。

正文:

在進(jìn)行iOS上開(kāi)發(fā),發(fā)現(xiàn)Flutter創(chuàng)建的項(xiàng)目不走didRegisterForRemoteNotificationsWithDeviceToken,起初以為是沒(méi)有設(shè)置UNUserNotificationCenterDelegate,后來(lái)發(fā)現(xiàn)AppDelegate是繼承于FlutterAppDelegate的,

也就是將原生的UIApplicationDelegate的方法都會(huì)被FlutterAppDelegate攔截,即使我們不實(shí)現(xiàn)didRegisterForRemoteNotificationsWithDeviceToken,我覺(jué)得應(yīng)該有兩種方法可以實(shí)現(xiàn):第一種是需要重寫父類的推送方法。第二種就是在dart文件中監(jiān)聽(tīng)系統(tǒng)代理,通過(guò)通道回調(diào)appdelegate來(lái)實(shí)現(xiàn),

下面是百度云推送,重寫父類代理的實(shí)現(xiàn):

在didFinishLaunchingWithOptions launchOptions: 中注冊(cè)原生交互channel

override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? ) - Bool {

? ? //Flutter Plugin插件注冊(cè)

? ? GeneratedPluginRegistrant.register(with: self);

? ? //調(diào)用appdelegate 的 設(shè)置、注冊(cè)遠(yuǎn)程推送

? ? self.requestAuthorization(application: application);

? ? //Flutter原生交互通道

? ? self.BPushChannel();

? ? //注冊(cè)BPush通道

? ? BPush.registerChannel(launchOptions, apiKey: BPushKey, pushMode: BPushMode.development, withFirstAction: "打開(kāi)", withSecondAction: "關(guān)閉", withCategory: nil, useBehaviorTextInput: true, isDebug: true);

? ? //禁用地理位置信息推送

? ? BPush.disableLbs();

? ? return super.application(application, didFinishLaunchingWithOptions: launchOptions);

}

//MARK:注冊(cè)遠(yuǎn)程推送通知

func requestAuthorization(application: UIApplication) {

? ? if #available(iOS 10.0, *) {

? ? ? ? UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate;

? ? ? ? UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in

? ? ? ? ? ? if granted == true {

? ? ? ? ? ? ? ? DispatchQueue.main.async {

? ? ? ? ? ? ? ? ? ? application.registerForRemoteNotifications()

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }

? ? } else if #available(iOS 8.0, *) {

? ? ? ? let types:UIUserNotificationType = [.badge , .alert , .sound]

? ? ? ? let settings:UIUserNotificationSettings = UIUserNotificationSettings(types: types, categories: nil)

? ? ? ? application.registerUserNotificationSettings(settings)

? ? } else {

? ? ? ? let types:UIRemoteNotificationType = [UIRemoteNotificationType.alert, UIRemoteNotificationType.badge, .sound]

? ? ? ? application.registerForRemoteNotifications(matching: types)

? ? }

}

//百度推送通道

func BPushChannel() - Void {

? ? //獲取系統(tǒng)的跟控制器

? ? let controller = self.window.rootViewController

? ? //建立rootViewController和Flutter的通信通道

? ? let pushChannel = FlutterMethodChannel.init(name: channelNameForPush, binaryMessenger:controller as! FlutterBinaryMessenger)

? ? //設(shè)置Method回調(diào)?FlutterMethodCall包含了method的Name,ID等信息,?FlutterResult是給Native和Flutter的通信回調(diào)

pushChannel.setMethodCallHandler { (FlutterMethodCall, FlutterResult) in

? ? ? ? print("pushChannel");

? ? }

? ? //綁定channelId到服務(wù)器

? ? let pushBind = FlutterMethodChannel.init(name:channelNameForPushBind, binaryMessenger: controller as! FlutterBinaryMessenger)

? ? pushBind.setMethodCallHandler { (FlutterMethodCall, FlutterResult) in

? ? ? ? //FlutterResult();結(jié)果回調(diào),回調(diào)的結(jié)果只能為string類型

? ? ? ? if(self.channelId.isEmpty){

? ? ? ? ? ? FlutterResult(FlutterMethodNotImplemented);

? ? ? ? } else{

? ? ? ? ? ? print("channelId",self.channelId);

? ? ? ? ? ? let dic : DictionaryString,String = ["channelId":self.channelId];

? ? ? ? ? ? let data = try? JSONSerialization.data(withJSONObject: dic, options: [])

? ? ? ? ? ? let encodingStr = String(data: data!, encoding: String.Encoding.utf8)!

//將信息傳到Flutter,

? ? ? ? ? ? FlutterResult(encodingStr);

? ? ? ? }

? ? }

}

// 重寫遠(yuǎn)程推送通知 注冊(cè)成功

override func application(_ application: UIApplication , didRegisterForRemoteNotificationsWithDeviceToken deviceToken:Data) {

? ? //? 向云推送注冊(cè) device token

? ? print("deviceToken = %@", deviceToken);

? ? BPush.registerDeviceToken(deviceToken as Data)

? ? // 綁定channel.將會(huì)在回調(diào)中看獲得channnelid appid userid 等

? ? BPush.bindChannel(completeHandler: { (result, error) - Void in

? ? ? ? if ((result) != nil){

? ? ? ? ? ? self.channelId = BPush.getChannelId();

? ? ? ? ? ? BPush.setTag("MyTag", withCompleteHandler: { (result, error) - Void in

? ? ? ? ? ? ? ? if ((result) != nil){

? ? ? ? ? ? ? ? }

? ? ? ? ? ? })

? ? ? ? }

? ? })

? ? super.application(application, didRegisterForRemoteNotificationsWithDeviceToken:deviceToken)

}

// 重寫注冊(cè)失敗

override func application(_ application: UIApplication , didFailToRegisterForRemoteNotificationsWithError error: Error ) {

? ? print("deviceToken = %@", error)

? ? super.application(application, didFailToRegisterForRemoteNotificationsWithError: error)

}

**如果解決了你的問(wèn)題,點(diǎn)個(gè)贊唄!**

文章題目:遠(yuǎn)程flutter,遠(yuǎn)程查看別人微信聊天記錄
本文路徑:http://muchs.cn/article10/phedgo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供靜態(tài)網(wǎng)站、ChatGPT、網(wǎng)站營(yíng)銷、云服務(wù)器、全網(wǎng)營(yíng)銷推廣手機(jī)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)