when I try to create a hotspot connection in my Xamarin.IOS project I get the following error returned in the description when using NEHotspotConfigurationManager :
Error Domain=NEHotspotConfigurationErrorDomain Code=8 \"internal error.\" UserInfo={NSLocalizedDescription=internal error.}
I have tried to connect to both the network in the office and my phone's wifi hotspot and both return the same message. I have enabled both the options "Accept WiFi Information" and "Hotspot" on both the App ID on the developer portal and also the same in the Entitlements.plist and still the same error. I'm using the code shown below.
public async void JoinNetwork()
{
NEHotspotConfiguration config = new NEHotspotConfiguration("CTIP");
config.JoinOnce = false;
var tcs = new TaskCompletionSource<NSError>();
NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(config, err => tcs.SetResult(err));
var error = await tcs.Task;
if (error != null)
{
PAGE.IOSErrorAlert(error.Description, this);
return;
}
}
Try you code as below
NEHotspotConfiguration config = new NEHotspotConfiguration("CTIP" ,passphrase , false);
config.JoinOnce = true;
var tcs = new TaskCompletionSource<NSError>();
NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(config, err =>
tcs.SetResult(err));
and try to restart your device ,this seems like a known issue on apple side .
Refer to
https://stackoverflow.com/a/47769497/8187800
https://developer.apple.com/forums/thread/107851
Related
I am working on a Xamarin app based on TX/RX serial com, particularly with Xamarin.iOS. I am trying to connect an Arduino to my iOS app, with Plugin.BLE NuGet package. At the time I try to start scanning for devices, the app crashes without debugging logs. This is the command that holds the Task for known device:
public async Task Button_ConnectBT()
{
connected = false;
_handler = CrossBluetoothLE.Current;
_adapter = CrossBluetoothLE.Current.Adapter;
devicelist = new ObservableCollection<IDevice>();
bt_state = "Not Connected";
if (!_adapter.IsScanning)
{
devicelist.Clear();
_adapter.ScanTimeout = 10000;
_adapter.ScanMode = ScanMode.LowPower;
_adapter.DeviceDiscovered += (s, a) =>
{
devicelist.Add(a.Device);
};
if(!_handler.Adapter.IsScanning)
await _adapter.StartScanningForDevicesAsync(); //Breaks here
foreach (var device in devicelist)
{
if (device.Id.ToString() == "96af0bb8-cafa-5b07-a0d2-79c01a414e7ee")
{
...
}
bt_state = "Connected";
}
}
Does anybody know why StartScanningForDevicesASync() is not working? Are there any permissions required by the ios app? If permissions are the impediment, how can I figure them out?
Thank you in advance.
Regards,
Raúl.
i programming an Application for my study.
I try to use gRPC in Xamarin.Forms.
The gRPC is in a seperate Libyry (.NET Standart 2.1).
If i use the code in WPF-Core Project every thing works fine.
But if I try to use the same in my Xamarin.Forms-Project the Connection don't work.
if I use the connectionString "http://my.server.com:5050" I get these Exception
Error starting gRPC call: unexpected end of stream on Connection{my.server.com:5050, proxy=DIRECT hostAddress=5.189.149.82 cipherSuite=none protocol=http/1.1} (recycle count=0)
if I the SSL Version"https://my.server.com:5050" I get these Exception
Error starting gRPC call: Connection closed by peer
Here is the Code of the gRPC-Libary
...
if (connectionString.Contains("http://"))
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
channel = GrpcChannel.ForAddress(connectionString);
client = new Haushaltsbuch.HaushaltsbuchClient(channel);
SuccsessReply reply = new SuccsessReply { Result = false };
try
{
reply = client.Login(new UserRequest
{
User = new GRPC_User
{
Username = username,
PassHash = passHash
}
});
}
catch (RpcException e) when (e.Status.Detail.Contains("The SSL connection could not be established"))
{
client = null;
throw new CommunicationException("Fehler mit SSL-Zertifikat des Servers", e);
}
catch (RpcException e)
{
client = null;
throw new CommunicationException("Server nicht erreichbar", e);
}
...
I am only a student and if I google, then it says that Xamarin Forms is supporting gRPC.
But why is it not working?
the .Android Project has the GRPC.Core package from NuGet istalled.
Solved it by Replacing
channel = GrpcChannel.ForAddress(connectionString);
with
if (connectionString.Contains("http://"))
{
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
string newConString = connectionString.Replace("http://", "");
return new Channel(newConString, ChannelCredentials.Insecure);
}
else
{
string newConString = connectionString.Replace("https://", "");
return new Channel(newConString, new SslCredentials());
}
It seems like the GrpcChannel Class isn't working on Andriod.
Update: May, 2021
Xamarin does not fully support gRPC, so be aware of this when developing your software on Xamarin.Forms.
Starting w/ gRPC version 2.34.X, gRPC has started partial support for Xamarin.Forms w/ Android and iOS devices.
Please see this for more information.
I seem to be unable to get any listing from / of the FTP server. (FileZilla is showing the directories and files).
I got this code:
FtpClient ftpConn = new FtpClient();
ftpConn.Host = FtpServer;
ftpConn.Port = FtpPort;
ftpConn.Credentials = new System.Net.NetworkCredential(Username, Password);
ftpConn.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
ftpConn.EncryptionMode = FtpEncryptionMode.Implicit;
ftpConn.ValidateCertificate += new FtpSslValidation(Client_ValidateCertificate);
ftpConn.BulkListing = false;
//ftpConn.DataConnectionType = FtpDataConnectionType.AutoPassive;
ftpConn.Connect();
FtpListItem[] FtpFolders = null;
FtpFolders = ftpConn.GetListing(Folder);
But it doesn't work. I tried the FTP options but didn't get any result.
Any more suggestions?
Based on your code,
You can't get any result because of fail to connect to FTP server.
Here is what you missed, refer to this: FAQ section of FluentFTP.
You may have certificate(*.crt, *.cer) file, bring it into your source code as below.
ftpConn.ClientCertificates.Add(new X509Certificate2(#"C:\ftpServer.crt"));
If your certificate file doesn't have root chain.
(for example, made by your self or in case of it is private cert file).
You need to add more specific code at,
ftpConn.ValidateCertificate += new FtpSslValidation(Client_ValidateCertificate);
private void Client_ValidateCertificate(FtpClient control, FtpSslValidationEventArgs e)
{
if (e.PolicyErrors == SslPolicyErrors.None || e.Certificate.GetRawCertDataString() == "Use this condition for your situation")
{
e.Accept = true;
}
else
{
if (e.PolicyErrors == SslPolicyErrors.RemoteCertificateChainErrors)
{
//In this case, you need to choose connect or not. If your certificate file doen't have root chain.
}
else
{
//throw new Exception($"{e.PolicyErrors}{Environment.NewLine}{GetCertificateDetails(e.Certificate)}");
}
}
}
PS : If your FTP service on Windows, you don't have any choice but if it work on linux or unix, You can use SFTP with "Renci.SshNet.
UPDATED : Now windows is support to openSSH, so we can use sftp.
Installation of OpenSSH For Windows Server 2019 and Windows 10
I am trying to transfer a file to my iphone using 32feet bluetooth, but cannot seem to get past the ObexWebResponse.
I have read many post on this but none of the solutions seem to work for me.
The Error i get is
// Connect failed
// The requested address is not valid in its context "address:Guid"
private BluetoothClient _bluetoothClient;
private BluetoothComponent _bluetoothComponent;
private List<BluetoothDeviceInfo> _inRangeBluetoothDevices;
private BluetoothDeviceInfo _hlkBoardDevice;
private EventHandler<BluetoothWin32AuthenticationEventArgs> _bluetoothAuthenticatorHandler;
private BluetoothWin32Authentication _bluetoothAuthenticator;
public BTooth() {
_bluetoothClient = new BluetoothClient();
_bluetoothComponent = new BluetoothComponent(_bluetoothClient);
_inRangeBluetoothDevices = new List<BluetoothDeviceInfo>();
_bluetoothAuthenticatorHandler = new EventHandler<BluetoothWin32AuthenticationEventArgs>(_bluetoothAutenticator_handlePairingRequest);
_bluetoothAuthenticator = new BluetoothWin32Authentication(_bluetoothAuthenticatorHandler);
_bluetoothComponent.DiscoverDevicesProgress += _bluetoothComponent_DiscoverDevicesProgress;
_bluetoothComponent.DiscoverDevicesComplete += _bluetoothComponent_DiscoverDevicesComplete;
ConnectAsync();
}
public void ConnectAsync() {
_inRangeBluetoothDevices.Clear();
_hlkBoardDevice = null;
_bluetoothComponent.DiscoverDevicesAsync(255, true, true, true, false, null);
}
private void PairWithBoard() {
Console.WriteLine("Pairing...");
bool pairResult = BluetoothSecurity.PairRequest(_hlkBoardDevice.DeviceAddress, null);
if (pairResult) {
Console.WriteLine("Success");
Console.WriteLine($"Authenticated equals {_hlkBoardDevice.Authenticated}");
} else {
Console.WriteLine("Fail"); // Instantly fails
}
}
private void _bluetoothComponent_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e) { _inRangeBluetoothDevices.AddRange(e.Devices); }
private void _bluetoothComponent_DiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs e) {
for (int i = 0; i < _inRangeBluetoothDevices.Count; ++i) {
if (_inRangeBluetoothDevices[i].DeviceName == "Uranus") {
_hlkBoardDevice = _inRangeBluetoothDevices[i];
PairWithBoard();
TransferFile();
return;
}
}
// no devices found
}
private void _bluetoothAutenticator_handlePairingRequest(object sender, BluetoothWin32AuthenticationEventArgs e) {
e.Confirm = true; // Never reach this line
}
// not working
// transfers a file to the phone
public void TransferFile() {
string file = "E:\\test.txt",
filename = System.IO.Path.GetFileName(file);
string deviceAddr = _hlkBoardDevice.DeviceAddress.ToString();
BluetoothAddress addr = BluetoothAddress.Parse(deviceAddr);
_bluetoothClient.Connect(BluetoothAddress.Parse(deviceAddr), BluetoothService.SerialPort);
Uri u = new Uri($"obex://{deviceAddr}/{file}");
ObexWebRequest owr = new ObexWebRequest(u);
owr.ReadFile(file);
// error:
// Connect failed
// The requested address is not valid in its context ...
var response = (ObexWebResponse)owr.GetResponse();
Console.WriteLine("Response Code: {0} (0x{0:X})", response.StatusCode);
response.Close();
}
The pairing and authentication works just fine, and I can get the BluetoothService.Handsfree to make a call for me but the transferring of the file fails. Not knowing what the actual error is, I tried almost every service available with no luck.
Can you help me figure out what is going on? This is my first attempt working with Bluetooth services so I still have a ton to learn.
Is it possible to transfer a file from iPhone to Windows desktop via Bluetooth?
However, in case you need to transfer media files (images, videos, etc) from Android device, you can use ObexListener class provided by 32Feet library for this purpose, and then you can simply call _obexListener.GetContext() method that will block and wait for incoming connections.
Once a new connection is received, you can save the received file to local storage, as shown in the below example:
ObexListener _listener = new ObexListener();
_listener.Start();
// This method will block and wait for incoming connections
ObexListenerContext _context = _listener.GetContext();
// Once new connection is received, you can save the file to local storage
_context.Request.WriteFile(#"c:\sample.jpg");
NOTE: When working with OBEX on Windows, make sure to disable the "Bluetooth OBEX Service" Windows service, in order not to let it handle the incoming OBEX requests instead of the desired application.
I walked away from this for a while. and started Trying to use xamiren but then had to create a virtual Mac so that I could have the apple store to just load software on my phone. From there xamerin 'should' work well but its another field and tons more to firgure out.
I have a winform program, now I need to enhance feature communicate with UWP app, so I added reference Windows.DLL and did some change for winform program, now I can call UWP app thru the method Launcher.LaunchUriAsync(), but any an exception on method Launcher.LaunchUriForResultsAsync(),
Could you provide me some advice? Thanks in advance.
Exception:
The operation identifier is not valid. (Exception from HRESULT: 0x800710DD)
Some Code:
// The protocol handled by the launched app
Uri testAppUri = new Uri("etrace.scanner:");
var supportStatus = await Launcher.QueryUriSupportAsync(testAppUri, LaunchQuerySupportType.Uri, "80a2fbc7-843e-46ca-a740-cbb1bc604d33_y890260wv9vv0");
if (supportStatus != LaunchQuerySupportStatus.Available)
{
// Check the app available or not.
}
var inputData = new ValueSet();
inputData["TestData"] = "Test data";
var optionsE = new LauncherOptions { TargetApplicationPackageFamilyName = "80a2fbc7-843e-46ca-a740-cbb1bc604d33_y890260wv9vv0" };
// Call APP successully.
bool success = await Launcher.LaunchUriAsync(testAppUri, optionsE, inputData);
Debug.WriteLine(success);
// Got an exception:
var result = await Launcher.LaunchUriForResultsAsync(testAppUri, optionsE, inputData);
You can use AppServiceConnections.
https://learn.microsoft.com/en-us/windows/uwp/launch-resume/how-to-create-and-consume-an-app-service
They're for communication with other apps for UWP and they're supported in Win32 and work the same.