当前位置: 首页 > news >正文

阿里百川 网站开发无锡网站建设收费

阿里百川 网站开发,无锡网站建设收费,如何用织梦仿制网站,国家企业年报网上申报系统背景MAUI的出现#xff0c;赋予了广大Net开发者开发多平台应用的能力#xff0c;MAUI 是Xamarin.Forms演变而来#xff0c;但是相比Xamarin性能更好#xff0c;可扩展性更强#xff0c;结构更简单。但是MAUI对于平台相关的实现并不完整。所以MASA团队开展了一个实验性项目…背景MAUI的出现赋予了广大Net开发者开发多平台应用的能力MAUI 是Xamarin.Forms演变而来但是相比Xamarin性能更好可扩展性更强结构更简单。但是MAUI对于平台相关的实现并不完整。所以MASA团队开展了一个实验性项目意在对微软MAUI的补充和扩展项目地址https://github.com/BlazorComponent/MASA.Blazor/tree/feature/Maui/src/Masa.Blazor.Maui.Plugin每个功能都有单独的demo演示项目考虑到app安装文件体积虽然MAUI已经集成裁剪功能但是该功能对于代码本身有影响届时每一个功能都会以单独的nuget包的形式提供方便测试现在项目才刚刚开始但是相信很快就会有可以交付的内容啦。前言本系列文章面向移动开发小白从零开始进行平台相关功能开发演示如何参考平台的官方文档使用MAUI技术来开发相应功能。介绍上一篇文章我们集成了个推的消息通知那么消息到达移动端之后除了会在通知栏显示之外在应用的角标也会显示未读消息的数量小红点然后用户点击查看消息之后这些数字角标也可以自动消除这个功能在MAUI中如何实现呢一、iOS部分思路https://developer.apple.com/documentation/uikit/uiapplication/1622918-applicationiconbadgenumber我们参考一下官方文档UIApplication下有一个applicationIconBadgeNumber的属性var applicationIconBadgeNumber: Int { get set }我们只需要给这个属性赋值具体的整数即可https://developer.apple.com/documentation/uikit/uiapplication/1622975-shared我们可以通过shared获取当前UIApplication的实例然后就可以给applicationIconBadgeNumber赋值了但是如果你直接这样做你会发现并没有效果因为 iOS 8 以后需要注册用户通知以获得用户的授权。https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/1649527-requestauthorization我们可以通过UNUserNotificationCenter的RequestAuthorization方法获取请求用户本地和远程的通知权限。开发步骤我们新建一个目录Badger并在下面新建MAUI类库项目Masa.Blazor.Maui.Plugin.Badger在Platforms下的iOS文件夹新建MasaMauiBadgerService部分类using UIKit; using UserNotifications; namespace Masa.Blazor.Maui.Plugin.Badger {public static partial class MasaMauiBadgerService{private static void PlatformSetNotificationCount(int count){// Requests the user’s authorization to allow local and remote notifications for your app.UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Badge, (r, e) {});// The number currently set as the badge of the app icon on the Home screen// Set to 0 (zero) to hide the badge number. The default value of this property is 0.UIApplication.SharedApplication.ApplicationIconBadgeNumber count;}} }RequestAuthorization方法有两个参数1、UNAuthorizationOptions 代表应用请求的授权选项这里我们使用Badge2、completionHandle 这是一个Action有两个参数第一个参数是一个bool值代表是否已授予授权第二个参数是一个NSError类型表示包含错误信息或未发生错误的对象。我们这里暂不处理出错的情况我们通过UIApplication.SharedApplication获取当前的UIApplication实例然后直接给ApplicationIconBadgeNumber 赋值这里如果我们想清除角标就直接赋值0即可。我们继续在项目根目录新建MasaMauiBadgerService类通过SetNotificationCount来调用不同平台的PlatformSetNotificationCount方法。namespace Masa.Blazor.Maui.Plugin.Badger {// All the code in this file is included in all platforms.public static partial class MasaMauiBadgerService{public static void SetNotificationCount(int count){PlatformSetNotificationCount(count);}} }二、安卓部分思路安卓部分比iOS相对复杂我们本着不造轮子的思想找了一个现成的aar包ShortcutBadger项目maven地址https://repo1.maven.org/maven2/me/leolin/ShortcutBadger开发步骤1、我们下载最新的ShortcutBadger-1.1.22.aar包并新建Android Java 库绑定项目Masa.Blazor.Maui.Plugin.BadgerBinding在根目录创建Jars文件夹并将下载的aar文件添加进去。添加进去的文件属性中生成操作默认选择的是AndroidLibrary如果不对请手动更正。右键生成这个项目这里很顺利没有任何报错。2、我们在Masa.Blazor.Maui.Plugin.Badger项目中引用Masa.Blazor.Maui.Plugin.BadgerBinding项目由于我们只有在安卓平台需要项目引用所以我们手动修改一下项目文件中的引用部分添加Android平台的判断。ItemGroup Condition$(TargetFramework) net7.0-androidProjectReference Include..\Masa.Blazor.Maui.Plugin.BadgerBinding\Masa.Blazor.Maui.Plugin.BadgerBinding.csproj //ItemGroup3、从 Android 8.0API 级别 26开始所有通知都必须分配到相应的渠道关于通知通道的信息可以参考以下官方文档https://developer.android.google.cn/training/notify-user/channels?hlzh-cnJava 代码private void createNotificationChannel() {// Create the NotificationChannel, but only on API 26 because// the NotificationChannel class is new and not in the support libraryif (Build.VERSION.SDK_INT Build.VERSION_CODES.O) {CharSequence name getString(R.string.channel_name);String description getString(R.string.channel_description);int importance NotificationManager.IMPORTANCE_DEFAULT;NotificationChannel channel new NotificationChannel(CHANNEL_ID, name, importance);channel.setDescription(description);// Register the channel with the system; you cant change the importance// or other notification behaviors after thisNotificationManager notificationManager getSystemService(NotificationManager.class);notificationManager.createNotificationChannel(channel);}}我们参照以上写法在Masa.Blazor.Maui.Plugin.Badger项目的Android平台目录下新建MasaMauiBadgerService 类添加一个CreateNotificationChannel方法using Android.App; using AndroidX.Core.App;namespace Masa.Blazor.Maui.Plugin.Badger {// All the code in this file is included in all platforms.public static partial class MasaMauiBadgerService{private static void CreateNotificationChannel(){if (OperatingSystem.IsAndroidVersionAtLeast(26)){using var channel new NotificationChannel(${Android.App.Application.Context.PackageName}.channel, Notification channel, NotificationImportance.Default){Description Masa notification channel};var notificationManager NotificationManager.FromContext(Android.App.Application.Context);notificationManager?.CreateNotificationChannel(channel);}}} }1、通过OperatingSystem.IsAndroidVersionAtLeast来判断当前的Android版本。2、NotificationChannel的创建方式与Java一致三个参数分别为ChannelIDname、Importance这里注意第三个参数代表重要性级别我们这里使用了NotificationImportance.Default。用户可见的重要性级别重要性Android 8.0 及更高版本紧急发出提示音并以浮动通知的形式显示IMPORTANCE_HIG高发出提示音IMPORTANCE_DEFAULT中无提示音IMPORTANCE_LOW低无提示音且不会在状态栏中显示IMPORTANCE_MIN3、Description 指定用户在系统设置中看到的说明。4、通过NotificationManager.FromContext 创建 notificationManager然后调用CreateNotificationChannel来创建通知通道。我们继续添加SetNotificationCount方法private static void PlatformSetNotificationCount(int count){ME.Leolin.Shortcutbadger.ShortcutBadger.ApplyCount(Android.App.Application.Context, count);NotificationCompat.Builder builder new(Android.App.Application.Context, ${Android.App.Application.Context.PackageName}.channel);builder.SetNumber(count);builder.SetContentTitle( );builder.SetContentText();builder.SetSmallIcon(Android.Resource.Drawable.SymDefAppIcon);var notification builder.Build();var notificationManager NotificationManager.FromContext(Android.App.Application.Context);CreateNotificationChannel();notificationManager?.Notify((int)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), notification);}1、调用ShortcutBadger的ApplyCount方法来添加角标2、创建NotificationCompat.Builder示例并以此设置角标显示数量SetNumber通知的标题SetContentTitle和内容SetContentText以及通知图标SetSmallIcon。3、调用我们刚写好的方法创建通知通道。4、通过NotificationManager.Notify方法在状态栏发布一条通知。该方法有两个参数第一个参数是一个int类型id这个id是通知的标识符在应用程序中应该唯一。这里需要注意如果你发布了相同id的通知并且前一个并没有取消那么该id对应的通知会被更新。第二个参数是一个notification 对象是通过NotificationCompat.Builder创建出来的。三、创建Demo项目1、新建一个MAUI Blazor项目BadgerSample,添加对Masa.Blazor.Maui.Plugin.Badger项目的引用2、添加Android权限修改Android平台目录中的AndroidManifest.xml文件添加必要的权限。?xml version1.0 encodingutf-8? manifest xmlns:androidhttp://schemas.android.com/apk/res/androidapplication android:allowBackuptrue android:iconmipmap/appicon android:roundIconmipmap/appicon_round android:supportsRtltrue/applicationuses-permission android:nameandroid.permission.ACCESS_NETWORK_STATE /uses-permission android:nameandroid.permission.INTERNET /uses-permission android:nameandroid.permission.POST_NOTIFICATIONS/uses-permission android:nameandroid.permission.READ_APP_BADGE /uses-permission android:namecom.android.launcher.permission.READ_SETTINGS/uses-permission android:namecom.android.launcher.permission.WRITE_SETTINGS/uses-permission android:namecom.android.launcher.permission.INSTALL_SHORTCUT /uses-permission android:namecom.android.launcher.permission.UNINSTALL_SHORTCUT / /manifest注意国内不同手机厂家可能需要额外的权限配置需要参考具体厂家的配置说明。3、修改Index.razor文件实际的使用场景应该是移动端接收消息推送在处理消息推送的方法内修改角标我们这里为了简化在页面直接通过按钮触发修改角标显示的数量。page / using Masa.Blazor.Maui.Plugin.Badger;h1Masa blazor badger sample/h1Masa blazor badger sample.button onclickOnIncrementClickedAdd/button button onclickOnClearClickedClear/button code{int count;private void OnIncrementClicked(){count;MasaMauiBadgerService.SetNotificationCount(count);}private void OnClearClicked(){count 0;MasaMauiBadgerService.SetNotificationCount(count);} }Android 演示演示机vivo x70 proiOS 演示演示机iPhone 14 iOS16 模拟器如果你对我们的开源项目感兴趣无论是代码贡献、使用、提 Issue欢迎联系我们
http://www.zqtcl.cn/news/786746/

相关文章:

  • 抚州市做棋牌网站邯郸信息港聊天室
  • 李静做的化妆品网站树莓派lamp WordPress
  • 建站之星网站建设系统个人网站有什么外国广告做
  • 残联网站建设概况专业产品画册设计公司
  • 德尔普的网站建设的价格windows2008做网站
  • 画品展现手机网站短网址生成器有哪些
  • 如何做好网站推广营销网站 需求
  • 济宁做网站大约多少钱做设计兼职的网站有哪些
  • 教务系统网站开发方法网站建设在哪里
  • 房产网站如何做手机在网上怎么创建自己的网站
  • 金华网站建设luopan公司网站模板图片
  • 建个购物网站网站建设公司合同
  • 建设银行企业版网站网站里的动态是如何制作
  • 360网站建设的目标是什么微信哪个公司开发
  • c++可以做网站吗极验 wordpress 表单
  • 电脑做系统都是英文选哪个网站找外贸客户的联系方式软件
  • 商城网站建设咨询建工社官网
  • 国土资源局网站建设制度蓝牙 技术支持 东莞网站建设
  • 12380网站建设建议上海网站推广服务
  • 做公司网站要提供什么企业门户app
  • 免费企业网站模板 php网站301跳转怎么做
  • 沭阳哪里有做网站推广的二手车网站源码下载
  • 网站建设添加视频教程wordpress做阿里巴巴国际站
  • 四川网站建设哪家专业辽宁招投标工程信息网
  • 小语种网站建设wordpress 上传图片不显示
  • 建网站什么网最好重庆制作网站公司简介
  • 中国建站平台邯郸现代建设集团网站
  • 爱站seo排名可以做哪些网站宁波网站怎么建设
  • 洛阳市伊滨区建设局网站企业集团网站源码
  • 做修图网站电脑配置wordpress后台登录页面美化