System.Threading.Tasks.TaskCanceledException: A task was canceled.
2017-11-05 14:46:31.228 Project.iOS[36807:4480015]
Unhandled Exception:
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00020] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:179
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.2.0.11/src/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.TaskAwaiter`
I am having hard time in handling the exception thrown by the following code when i try to debug on ios.11 emulator, but this code works fine in android.
private async Task<Plugin.Geolocator.Abstractions.Position> GetPositionAsync() {
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 50;
TimeSpan ts = new TimeSpan((Int32)10000);
_position = await locator.GetPositionAsync(timeout: ts);
return _position;
}
I have followed all the instructions mentioned in various websites related to #jamesmontemagno/Xamarin.Plugins/Geolocator/ but no luck. I have made sure my info.plist consist of following code:
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>This app needs access location when open and in the background.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Need location for geolocator plugin.</string>
<key>RequestWhenInUseAuthorization</key>
<string>Need location for geolocator plugin.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Need location for geolocator plugin.</string>
All i am trying to achieve is obtaining current location on all three platforms (IOS, Android, Windows) through Xamarin.Froms. Android is working perfectly but IOS is where i got stuck. Any type of help is appreciated.
After comparing with the official sample , I found the issue was that the timeout parameter you set is too short for the task completion, so it canceled every time.
Solution :
await locator.GetPositionAsync(TimeSpan.FromSeconds(10));
Related
this is the first time I'm trying to write a request to you. Normaly I had could resolve most of the problems thanks to stackoverflow and others.
I developed an Xamarin.Forms App which runs on Android perfectly but when I try to deploy it to iOS (physical iPhone 8) it keeps breaking.
After searching for hours and trying diffrent things I hope someone can read out of the Code whats the matter...
I tried as well to set breakpoints in the appdelegate or first Page but after some seconds everthing breaks with this information:
2021-08-27 18:39:24.004 Xamarin.PreBuilt.iOS[4330:1030659] Xamarin.iOS: Successfully received USB connection from the IDE on port 10000, fd: 6
2021-08-27 18:39:24.007 Xamarin.PreBuilt.iOS[4330:1030659] Xamarin.iOS: Processing: 'start profiler: no'
2021-08-27 18:39:24.007 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Profiler not loaded (disabled)
Loaded assembly: /private/var/containers/Bundle/Application/092BCD0C-2FC9-4F1B-A83E-29D87ACD245E/SHAPP.iOS.app/Xamarin.iOS.dll [External]
2021-08-27 18:39:24.334 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'SHAPP' (culture: '')
2021-08-27 18:39:24.334 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'SHAPP' (culture: '')
Loaded assembly: /private/var/mobile/Containers/Data/Application/6FE32CF0-AE4D-41A2-BBBA-EAD56133AA7E/Documents/SHAPP.iOS.content/Xamarin.Forms.Core.dll [External]
2021-08-27 18:39:24.404 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'FFImageLoading' (culture: '')
2021-08-27 18:39:24.404 Xamarin.PreBuilt.iOS[4330:1030624] Xamarin.iOS: Unable to locate assembly 'FFImageLoading' (culture: '')
Loaded assembly: /private/var/mobile/Containers/Data/Application/6FE32CF0-AE4D-41A2-BBBA-EAD56133AA7E/Documents/SHAPP.iOS.content/FFImageLoading.Platform.dll [External]
....
[0:] Failed to force load assembly /var/mobile/Containers/Data/Application/6FE32CF0-AE4D-41A2-BBBA-EAD56133AA7E/Documents/SHAPP.iOS.content/Forms9Patch.dll. Type:Forms9Patch.PopupLayerEffect. Exception: 'You must call Xamarin.Forms.Forms.Init(); prior to using this property.'. Callstack: ' at Xamarin.Forms.Device.get_PlatformServices () [0x00007] in D:\a\1\s\Xamarin.Forms.Core\Device.cs:87
at Xamarin.Forms.Device.GetAssemblies () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Device.cs:245
at Xamarin.Forms.DependencyService.Initialize () [0x00021] in D:\a\1\s\Xamarin.Forms.Core\DependencyService.cs:103
at Xamarin.Forms.DependencyService.Get[T] (Xamarin.Forms.DependencyFetchTarget fetchTarget) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\DependencyService.cs:28
at Forms9Patch.Settings.ConfirmInitialization () [0x00008] in C:\Users\ben\Development\Xamarin\Forms9Patch\Forms9Patch\Forms9Patch\Models\Settings.cs:116
at Forms9Patch.PopupLayerEffect..cctor () [0x00000] in C:\Users\ben\Development\Xamarin\Forms9Patch\Forms9Patch\Forms9Patch\Effects\PopupLayerEffect.cs:19 '
...
[0:] An error occurred: 'Could not create an native instance of the type 'Airbnb.Lottie.LOTAnimationView': the native class hasn't been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.'. Callstack: ' at Foundation.NSObject.InitializeObject (System.Boolean alloced) [0x0002e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:247
at Foundation.NSObject..ctor (Foundation.NSObjectFlag x) [0x0000d] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:147
at UIKit.UIResponder..ctor (Foundation.NSObjectFlag t) [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/ios/native/UIKit/UIResponder.g.cs:74
at UIKit.UIView..ctor (Foundation.NSObjectFlag t) [0x00000] in
...
--- End of stack trace from previous location where exception was thrown ---
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:86
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0000e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:65
at SHAPP.iOS.Application.Main (System.String[] args) [0x00001] in C:\VisualCSharp\MyProjects\SHAPP\SHAPP.iOS\Main.cs:17
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 '
Die App wurde beendet.
Thanks Jason and Saamer,
as you wrote i did try to fix that error prior to my request. But I could not find a way.
My AppDelegate looks like that:
using Foundation;
using Lottie.Forms.Platforms.Ios;
using UIKit;
namespace SHAPP.iOS
{
// The UIApplicationDelegate for the application. This class is responsible for launching the
// User Interface of the application, as well as listening (and optionally responding) to
// application events from iOS.
[Register("AppDelegate")]
public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
{
//
// This method is invoked when the application has loaded and is ready to run. In this
// method you should instantiate the window, load the UI into it and then make the window
// visible.
//
// You have 17 seconds to return from this method, or iOS will terminate your application.
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
global::Xamarin.Forms.Forms.Init();
Xamarin.Forms.Forms.Init();
Forms9Patch.iOS.Settings.Initialize(this);
FFImageLoading.Forms.Platform.CachedImageRenderer.Init();
ZXing.Net.Mobile.Forms.iOS.Platform.Init();
// ObjCRuntime.Class.ThrowOnInitFailure = false;
LoadApplication(new App());
//AnimationViewRenderer.Init();
return base.FinishedLaunching(app, options);
}
}
}
So nothing to special, I did even try to set the old Lottie Init, but it did not help. As well I tryed to cancel all nuget Lottiefiles in iOS and to reinstall them, afterwards I cleaned the projects and restartet the build, same error.
Only working thing is to completly cancel Lottieusage.
The Lottie-XAML I use look's like that:
<lottie:AnimationView
Animation="14525-plumbers.json"
AutoPlay="True"
RepeatCount="3"
RepeatMode="Restart"
CacheComposition="True"
HeightRequest="500"
VerticalOptions="Start"
HorizontalOptions="Center"
IsVisible="true"
/>
If I comment it out everything works fine.
The LottieAnimationfile is in my RessourcesFolder (BundledRessource) as well as in the main folder.
Folders iOS and LottieFiles
Gentlement any ideas, what could be wrong? Thanks in advance
As Jason mentioned, you need to add that line in the AppDelegate, as you can see in this example
But you have another error too as you can read the error message at the end of the StackTrace you shared:
An error occurred: 'Could not create an native instance of the type 'Airbnb.Lottie.LOTAnimationView': the native class hasn't been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.'. Callstack: ' at Foundation.NSObject.InitializeObject (System.Boolean alloced) [0x0002e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:247
at Foundation.NSObject..ctor (Foundation.NSObjectFlag x) [0x0000d] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:147
What Lottie package are you using? Is it this one? Are you using the latest version?
You have to make sure that you add the iOS version of the Lottie package to the iOS project.
I have a app crash when i'm picking a image. i'm using image_picker:0.5.0+7
with any ImageSource it's crash the app.
File _fileState;
Future getImage(ImageSource imageSource) async{
// using your method of getting an image
final File image = await ImagePicker.pickImage(source: imageSource);
print("path:: ");
setState(() {
// print("path:: "+image.path);
_fileState = image;
});
}
Shutting down VM
E/AndroidRuntime(16049): FATAL EXCEPTION: main
E/AndroidRuntime(16049): Process: com.grain.test_camera, PID: 16049
E/AndroidRuntime(16049): java.lang.RuntimeException: Unable to resume activity
{com.grain.test_camera/com.grain.test_camera.MainActivity}:
java.lang.RuntimeException: Failure deliver
ing result ResultInfo{who=null, request=2342, result=-1, data=Intent {
dat=content://com.android.providers.media.documents/document/image:25272
flg=0x1 }} to activity {com.grain.test
_camera/com.grain.test_camera.MainActivity}: java.lang.IllegalStateException: Received image from picker that was
not requested
E/AndroidRuntime(16049): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3506)
E/AndroidRuntime(16049): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3546)
E/AndroidRuntime(16049): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2795)
E/AndroidRuntime(16049): at android.app.ActivityThread.-wrap12(ActivityThread.java)
E/AndroidRuntime(16049): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1527)
E/AndroidRuntime(16049): at android.os.Handler.dispatchMessage(Handler.java:110)
E/AndroidRuntime(16049): at android.os.Looper.loop(Looper.java:203)
E/AndroidRuntime(16049): at android.app.ActivityThread.main(ActivityThread.java:6251)
E/AndroidRuntime(16049): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(16049): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1063)
E/AndroidRuntime(16049): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:924)
E/AndroidRuntime(16049): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2342,
result=-1, data=Intent { dat=content://com.android.provid
ers.media.documents/document/image:25272 flg=0x1 }} to activity {com.grain.test_camera/com.grain.test_camera.MainActivity}:
java.lang.IllegalStateException: Received image from picke
r that was not requested
I do not know what I can do please help me
It may be related to AndroidX compability. You have to avoid AndroidX or migrate your project to AndroidX.
There were a breaking change after version 0.5.0
image_picker plugin does not support camera permission condition anymore. For instance, when we try to access camera from an app, the app asks us for permission.
Now, since image_picker plugin has removed that condition, we need to ask the permission manually using permission_handler plugin. Read more details about this change here
Use this plugin to add the request manually ie runtime and you should be able to get rid of this crash.
I found out that in developer mode, phone close main activity of flutter because of an option in developer options this comment from author of package is
On Android, the MainActivity can be killed and restarted after launching the image picker for various of reasons. this can be tested by selecting `don't keep activities alive' option in the developer options in phone's setting app.
then when I disable this option I get result in every device that I checked. link of this description is here. I hope it works for you.
i had the same error
image picker crash on selecting an image
i solved this by using images_picker this will work instead of image_picker
I had problems with the IOS simulator.
For anyone having the same problem, I needed to set the permissions messages in Info.plist
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs to access your photo galery.</string>
<key>NSCameraUsageDescription</key>
<string>This app needs to access your camera.</string>
It seems image_picker documentation has been updated.
You would have to use retrieveLostData when the app restarts (migrate to AndroidX else you may get a force close error)
Future<void> retrieveLostData() async {
final LostDataResponse response = await ImagePicker.retrieveLostData();
if (response == null) {
return;
}
if (response.file != null) {
setState(() {
if (response.type == RetrieveType.video) {
_handleVideo(response.file);
} else {
_handleImage(response.file);
}
});
} else {
_handleError(response.exception);
}
}
I have made an app which is using audio lip sync and it runs fine on android, and mac but when I build it for iOS it is keep giving me this error:
DllNotFoundException: Unable to load DLL 'OVRLipSync': The specified
module could not be found. at OVRLipSync.ovrLipSyncDll_Initialize
(Int32 samplerate, Int32 buffersize) [0x00000] in :0
at OVRLipSync.Initialize (Int32 sampleRate, Int32 bufferSize)
[0x00000] in :0 at OVRLipSync.Awake () [0x00000]
in :0 (Filename: currently not available on
il2cpp Line: -1)
Is this a known issue?? or any new bug in the latest package??
As it turns out Oculus Lip Sync doesn't support iOS yet and they don't plan to do it in the near future.
Hope it helps someone else.
I am getting this error:
System.NullReferenceException: Object reference not set to an instance
of an object
at MonoTouch.Design.Client.IPhoneDesignerSession +
<MaybeConvertToLatestXcode>c__async5.MoveNext () [0x0004c] in
/Users/builder/data/lanes/4470/6c2f6737/source/md-
addins/Xamarin.Designer.iOS/MonoTouch.Design.Client/
IPhoneDesignerSession.cs:774
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()
[0x0000c] in /private/tmp/source-mono-d15-3/bockbuild-d15-
3/profiles/mono-mac-xamarin/build-root/mono-
x64/mcs/class/referencesource/mscorlib/system/runtime/
exceptionservices/exceptionservicescommon.cs:151
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
(System.Threading.Tasks.Task task) [0x00037] in /private/tmp/source-
mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-
x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/
TaskAwaiter.cs:187
I cannot view my storyboard.
I think it better to address this issue to xamarin support.
For now, you can try to open your storyboard in XCode.
I am currently developing an application that needs to communicate with a MQTT server via a socket connection. As the System.Net.Sockets API tends to misbehave when switching from a WiFi network to a 3G network (and this happens quite a lot actually) I've decided to give the CFStream API a try. In doing so I've encountered several issues, as follows.
Creating a pair of streams with CreatePairWithSocketToHost crashes the application as soon as I call Open() on either one of the streams.
CFStream.CreatePairWithSocketToHost(GetEndPoint(), out mReadStream, out mWriteStream);
mReadStream.EnableEvents(CFRunLoop.Current, CFRunLoop.CFDefaultRunLoopMode);
mWriteStream.EnableEvents(CFRunLoop.Current, CFRunLoop.CFDefaultRunLoopMode);
mReadStream.Open();
mWriteStream.Open();
The crash occurs regardless of whether I call EnableEvents() or not. The exception is:
[ERROR] FATAL UNHANDLED EXCEPTION: MonoTouch.CoreFoundation.CFException: The operation couldn’t be completed. Cannot allocate memory
at MonoTouch.CoreFoundation.CFStream.CheckError () [0x0000f] in /Developer/MonoTouch/Source/monotouch/src/shared/CoreFoundation/CFStream.cs:236
at MonoTouch.CoreFoundation.CFStream.Open () [0x00040] in /Developer/MonoTouch/Source/monotouch/src/shared/CoreFoundation/CFStream.cs:248
at TestCfNework.RootViewController.TestCreatePairToHost () [0x00041] in /Users/adrian/Projects/TestCfNework/TestCfNework/RootViewController.cs:79
at TestCfNework.RootViewController.ViewDidLoad () [0x00000] in /Users/adrian/Projects/TestCfNework/TestCfNework/RootViewController.cs:24
at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00008] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIWindow.g.cs:124
at TestCfNework.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x0002e] in /Users/adrian/Projects/TestCfNework/TestCfNework/AppDelegate.cs:32
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
at TestCfNework.Application.Main (System.String[] args) [0x00000] in /Users/adrian/Projects/TestCfNework/TestCfNework/Main.cs:17
Creating a pair of streams with CreatePairWithSocket by first creating and connecting a CFSocket allows for Open() to proceed without crashing, but CanAcceptBytesEvent is never fired, CanAcceptBytes() is always false and any write attempt fails with a timeout.
mSocket = new CFSocket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp,
CFRunLoop.Current);
mSocket.ConnectEvent += delegate {
Console.WriteLine("Socket connected");
CFStream.CreatePairWithSocket(mSocket, out mReadStream, out mWriteStream);
mReadStream.EnableEvents(CFRunLoop.Current, CFRunLoop.CFDefaultRunLoopMode);
mWriteStream.EnableEvents(CFRunLoop.Current, CFRunLoop.CFDefaultRunLoopMode);
mReadStream.Open();
mWriteStream.Open();
mWriteStream.CanAcceptBytesEvent += delegate {
Console.WriteLine("Write stream can now accept data");
};
mWriteStream.ErrorEvent += delegate {
Console.WriteLine(mWriteStream.GetError());
};
};
mSocket.Connect(GetEndPoint(), 0);
Creating a pair of streams using CreatePairWithPeerSocketSignature is the only one that actually produces a pair of streams that I can work with: opening does not crash and I am allowed to write to and read from respectively.
The API behaves this way both on the simulator and on the actual device. So, is this something I am doing wrong? Is it a MonoTouch issue? Is it a bug in the CFStream API itself?
MonoTouch version: 6.0.1.
XCode version: 4.5.
I wrote most the CFNetwork code in MonoMac / MonoTouch, so I should hopefully be able to help you with this :-)
Your code looks ok to me. It works fine with MonoMac (stand-alone Cocoa application on the Mac), but I see the same problem with MonoTouch. Opening the read stream sometimes works, sometimes not, opening the write stream always fails.
CFStream.CreatePairWithSocketToHost() calls CFStreamCreatePairWithSocketToCFHost().
After adding a new overloaded version:
public static void CreatePairWithSocketToHost (string host, int port,
out CFReadStream readStream,
out CFWriteStream writeStream)
which calls CFStreamCreatePairWithSocketToHost(), this is now working fine.
I just had a look at this and found the problem, will have a fix for it shortly.
About your second problem, the CFSocket API is hitting the same code path internally, so it's also affected by this bug.
To wake up the 3G network, you want to use:
http://iosapi.xamarin.com/?link=T%3aMonoTouch.ObjCRuntime.Runtime%2fM%2fStartWWAN