Xamarin-ios 分享 &接收音频文件 [英] Xamarin-ios share & receive audio file

查看:42
本文介绍了Xamarin-ios 分享 &接收音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将我的应用中的音频文件共享给其他应用并从其他应用接收音频文件?

How can I share a audio file from my app to other apps and receive audio files from other apps?

我想要这样的功能:

我无法附加音频文件.这是代码片段:

I am unable to attach a audio file. Here is the code snippet:

var fileData = NSUrl.FromFilename(path);  
var item = UIActivity.FromObject(@"<html><body><b>URL</b>: <a href='" + url + "'>" + url + "</a></body></html>");// NSObject.FromObject(uiImage);
var activityItems = new[] { fileData };
NSString message = (NSString)"Test";
var activityController = new UIActivityViewController(activityItems, null);
activityController.SetValueForKey(NSObject.FromObject("The subject value"), new NSString("subject"));
var topController = UIApplication.SharedApplication.KeyWindow.RootViewController;
while (topController.PresentedViewController != null)
{
    topController = topController.PresentedViewController;
}
topController.PresentViewController(activityController, true, () => { });

如果文件附加为邮件,我还想添加主题和正文.

I would also like to add subject and body if file attached as mail.

试过了,但没有运气,出现错误.:

tried this but no luck, getting an error.:

activityController.SetValueForKey(NSObject.FromObject("The subject value"), new NSString("subject"));
activityController.SetValueForKey(NSObject.FromObject("The body value"), new NSString("body"));

我还想接收其他应用共享的音频文件.我已经使用依赖服务和意图过滤器在 android 中完成了这个功能.对于 android,代码已添加到 mainactivity.cs 中,我使用意图过滤器来接受来自其他应用程序的音频文件.如何在 iOS 中做到这一点?

Also I would like to receive audio files shared by other apps. I have done the feature in android using dependency services and intent filters. For android the code is been added to mainactivity.cs where I use intent filters to accept audio files from other app. How to do that in iOS?

推荐答案

您可以通过在主应用程序和扩展程序之间共享数据来共享和接收文件.请注意,您的应用和应用扩展应该属于同一个应用组.

You can share and receive files by sharing data between the main app and an extension. Note that your app and the app extension should belong to the same app group.

  1. 应用扩展要点 https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/index.html#//apple_ref/doc/uid/TP40014214-CH20-SW1
  2. 扩展简介 https://developer.xamarin.com/guides/ios/platform_features/introduction_to_extensions/#Overview
  3. 通过示例分享概览http://www.technetexperts.com/mobile/share-extension-in-ios-application-overview-with-example/

这篇关于Xamarin-ios 分享 &amp;接收音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆