首页 文章 精选 留言 我的

精选列表

搜索[原生统一],共10000篇文章
优秀的个人博客,低调大师

GitHub 发布 AI 原生开发工具 GitHub Copilot Workspace

GitHub 宣布推出 GitHub Copilot Workspace 技术预览版。 通过 Copilot Workspace,开发者可以用自然语言进行头脑风暴、规划、构建、测试和运行代码。 其工作原理如下: 一切从任务开始 从一个 GitHub Issue、Pull Request 或仓库中打开 GitHub Copilot Workspace。(截图显示了 octoacademy 仓库中的一个 Issue。) 计划的制定 从任务进展到规范化步骤,概述你想通过 Copilot Workspace 实现的目标。这些步骤是可编辑的,允许你反复迭代。 全面可编辑 Copilot Workspace 提供的所有内容,从计划到代码,都可以完全编辑,使你能不断调整,直到对计划满意。你也可以通过集成终端运行测试、构建等步骤。 直接运行 计划完善后,你可以在 Copilot Workspace 中运行代码,并在 Codespace 中调整,直到对最终结果满意。你还可以通过链接分享 Workspace,使团队成员查看你的工作并进行迭代。 提交与审查 完成后,提交 Pull Request,运行 GitHub Actions 和代码扫描,并请求团队成员进行审查。他们可以通过 Copilot Workspace 查看你从构思到代码的全过程。 移动兼容 GitHub Copilot Workspace 支持在任何设备上使用,使你可以随时随地进行开发。

优秀的个人博客,低调大师

MASA MAUI Plugin (十)iOS消息推送(原生APNS方式)

背景 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技术来开发相应功能。 介绍 Apple 推送通知服务(Apple Push Notification service),简称 APNs。与之前Android使用个推不同,由于APNs国内可用,所以我们可以直接使用APNs来实现远程消息推送,不依赖其他第三方组件和服务。我们这里推送使用的是p8证书,p8证书相对p12证书来讲,更灵活,而且没有p12证书有效期1年的限制。 一、实现方式 一、申请p8证书 https://developer.apple.com/ 1、登录开发者中心,点击右上角Account,找到Keys管理。 2、在顶部点击+号。 3、勾选APNs服务,并输入Key名称,下一步Continue。 4、点击Register。 5、记录Key ID,并下载证书,得到AuthKey_xxxxxxxxxx.p8证书文件。 6、获取Team ID,Account界面点击Membership details 二、编写MAUI实现代码 参考官方文档:https://developer.apple.com/documentation/usernotifications/registering_your_app_with_apns 1、首先需要先开启App消息推送的能力 我们新建一个iOSPush 文件夹,并在文件夹下面新建MauiBlazor项目iOSPushSample (由于受打包长度影响,项目名称和文件夹名称,我这里尽量简短。路径长度超过255会导致编译时提示部分文件找不到。) 我们找到Platforms->iOS->Info.plist文件,双击用默认的iOS清单编辑器打开,勾选“启用后台模式”和“远程通知”。这项操作会在Info.plist文件中添加如下信息: <key>UIBackgroundModes</key> <array> <string>remote-notification</string> </array> 在开发环境,你需要以下的额外配置。 如果你的项目已经使用了Entitlements.plist文件,双击打开改文件,并勾选“推送通知”。 如果没有这个文件,那么新建这个文本文件,内容如下: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>aps-environment</key> <string>development</string> </dict> </plist> 注意:这项配置的目的是在development环境支持推送,如果在项目发布的时候,MAUI不会自动清除,需要手动关闭或注释掉这项配置,否则会报错。 2、编写实现代码 参考文档 https://developer.apple.com/documentation/usernotifications/registering_your_app_with_apns 我们首先需要将App注册到APNs并获取唯一的device token。在iOS中需要调用UIApplication 中通过registerForRemoteNotifications() 方法,实现注册,如果注册成功,就可以在delegate的application(_:didRegisterForRemoteNotificationsWithDeviceToken:) 方法中获取device token。如果注册失败,会触发application(_:didFailToRegisterForRemoteNotificationsWithError:) 方法。 Swift代码 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch.you’re UIApplication.shared.registerForRemoteNotifications() return true } func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { self.sendDeviceTokenToServer(data: deviceToken) } func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { // Try again later. } 我们开始编写代码 向APNs注册设备 首先在iOS->AppDelegate.cs 类中,重写FinishedLaunching 方法,在应用启动之后进行注册。 [Register("AppDelegate")] public class AppDelegate : MauiUIApplicationDelegate { protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { UNUserNotificationCenter center = UNUserNotificationCenter.Current; var options = UNAuthorizationOptions.Alert | UNAuthorizationOptions.Sound | UNAuthorizationOptions.CriticalAlert; // Request notification permissions from the user center.RequestAuthorization(options, (bool success, NSError error) => { // Handle approval } ); UIApplication.SharedApplication.RegisterForRemoteNotifications(); return base.FinishedLaunching(application, launchOptions); } } 应用启动时应立即请求通知权限,方法是将以下代码添加到FinishedLaunchingAppDelegate 所需通知类型 (UNAuthorizationOptions) 的方法: UNUserNotificationCenter 仅适用于 iOS 10+,但是考虑到基本没人用低于10的版本了,这里我们就不做版本检查了 用户可以批准应用的三个不同级别的通知请求: 横幅显示-Alert 。 声音警报-Sound 。 对应用图标进行错误设置-CriticalAlert。 请求权限结束后我们通过 UIApplication.SharedApplication.RegisterForRemoteNotifications(); 向APNs注册。 注册成功后我们通过application:didRegisterForRemoteNotificationsWithDeviceToken: 方法获取device token,但是由于这个方法是在UIApplication下,但是我们的AppDelegate是继承自 MauiUIApplicationDelegate ,默认没有这个方法,我们可以通过Export特性,导出我们需要的方法,继续在AppDelegate中添加 [Export("application:didFailToRegisterForRemoteNotificationsWithError:")] public void FailedToRegisterForRemoteNotifications(UIKit.UIApplication application, NSError error) { Console.WriteLine("FailedToRegisterForRemoteNotifications"); } [Export("application:didRegisterForRemoteNotificationsWithDeviceToken:")] public void RegisteredForRemoteNotifications(UIKit.UIApplication application, Foundation.NSData deviceToken) { var token = ExtractToken(deviceToken); Preferences.Default.Set("PushToken", token); Console.WriteLine(token); } private string ExtractToken(NSData deviceToken) { if (deviceToken.Length == 0) return null; var result = new byte[deviceToken.Length]; System.Runtime.InteropServices.Marshal.Copy(deviceToken.Bytes, result, 0, (int)deviceToken.Length); return BitConverter.ToString(result).Replace("-", ""); } ExtractToken是将返回的deviceToken解析为推送可用的字符串。 我们通过Preferences.Default.Set将token存储起来,方便在登录等业务中使用。 接收远程推送 接收推送的消息是通过**application:didReceiveRemoteNotification:fetchCompletionHandler:**实现的 [Export("application:didReceiveRemoteNotification:fetchCompletionHandler:")] public void DidReceiveRemoteNotification(UIKit.UIApplication application, NSDictionary userInfo, Action<UIKit.UIBackgroundFetchResult> completionHandler) { foreach (var item in userInfo) { var alertMsg = ((NSDictionary)item.Value)["alert"]; Console.WriteLine($"alertMsg:{alertMsg}"); } Console.WriteLine("DidReceiveRemoteNotification"); } 其实我们在方法内部不需要写任何代码,就可以实现基本的推送功能。但如果想处理推送过来的消息,可以通过NSDictionary类型userInfo中拿到。这里示例从alert中拿到具体的消息内容,并打印。 三、编写演示代码 我们修改Index.razor,通过点击按钮获取设备Token @page "/" <button @onclick="GetDeviceToken">Get Device Token</button> <text>@deviceToken</text> @code { private string deviceToken { get; set; } private void GetDeviceToken() { deviceToken= Preferences.Default.Get("PushToken",string.Empty); } } 四、服务端测试 我们可以通过个推的在线测试工具,配置好p8证书和其他参数。 我这里写了一个命令行的测试程序,这里使用了第三方的PushNotifications.Server包 using PushNotifications.Server.Apple; Console.WriteLine("Hello, World!"); IApnsClient apnsClient = new ApnsClient(new ApnsJwtOptions { CertContent = "-----BEGIN PRIVATE KEY-----\r\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n-----END PRIVATE KEY-----", KeyId = "LUxxxxxxxx", TeamId = "V4xxxxxxxx", BundleId = "com.iOSPush.Sample", UseSandbox = true }); var apnsRequest = new ApnsRequest(ApplePushType.Alert) .AddToken("47006118F8xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") .AddSound() .AddAlert("MASA", $"Message @ {DateTime.Now}", $"Message @ {DateTime.Now}"); var apnsResponse = await apnsClient.SendAsync(apnsRequest); Console.ReadKey(); 五、演示效果 可以看出,应用打开的状态不会收到推送,后台运行或者划掉关闭都可以收到通知。 如果你对我们的 MASA Framework 感兴趣,无论是代码贡献、使用、提 Issue,欢迎联系我们

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册