EnsureUIThread equivalent in Xamarin.Android (Mono for Android)? - xamarin.android

I've found a chain of methods in an Android app where RunOnUiThread is used to call other methods that also wrap their contents in RunOnUiThread. I would like to bake in the assumption that the method will only be called from another method that acquired the UI thread already and throw an exception when that condition isn't met. Xamarin.iOS exposes UIApplication.EnsureUIThread, which handles this nicely.
Is there an equivalent to the Xamarin.iOS (MonoTouch) UIApplication.EnsureUIThread in Xamarin.Android with similar behavior?

I found on the Xamarin Forum a post by Jonathan Pryor that says the following property:
SynchronizationContext.Current
is only non-null on the UI thread. Thus you could write a custom method that can check that property for null. Then throw an exception as desired.

Related

WARNING: CLSLog has been used before (or concurrently with) Crashlytics initialization and cannot be recorded

I've enabled crashlytics and trying to log with following code. I'm getting this warning. Can't figure out what this warning is and how to fix it.
In other words how do I log using CLSNSLogv?
Crashlytics:Crash] WARNING: CLSLog has been used before (or concurrently with) Crashlytics initialization and cannot be recorded. The message was:
CLSNSLogv("load() %# %d", getVaList(["Array count:", self.array.count]))
I'm the person that wrote that error message in the Crashlytics SDK :) However, I no longer work with that group and it's been a long time since I worked on that project. So, your best bet is to reach out to their support people.
Unless things have changed internally, the error message is telling you exactly what's up. Your use of CLSLog isn't the issue. The problem is the timing of its invocation. You cannot use the CLSLog family of functions until after the Crashlytics SDK has been fully initialized. It initializes synchronously. So, you can safely use CLSLog on the very next line after the Crashlytics SDK initialization call.
Perhaps you are invoking CLSLog in a function that's called asynchronously during startup?
Or, maybe you are initializing Crashlytics on a background thread? There are situations that cannot be reliably handled if you init the SDK asynchronously. I wouldn't recommend it, personally, but that's a call you have to make. I just want to make sure you understand the performance/correctness tradeoffs.

Remove Unused Methods from xcode ios

I am using xcode 9 with objective c. And i want to remove unused variable and methods from classes. I am also use this way but xcode do not warning of unused methods etc. How to find out?
Unfortunately unlike C functions, getting a list of unused objc methods in the form of warnings in Xcode is tricky due to the dynamic runtime environment. Your code might, for example,create a selector from a string and then call that selector on a class or instance of one etc.
One approach I've used, however it's time consuming depending on the size of the class(es), is to open the assistant editor and position the cursor over the method you wish to inspect and select callers (see below image. Normally the default selection is counterparts).
If there are no callers of the method then the editor shows no results.
However if you do this be aware no results will also show for IBActions and overrides in subclasses of iOS frameworks etc. You need to really know the code to determine if 'no results' really means no callers!

How to wrap existing iOS code in a new Appcelerator module?

This seems like a basic request, but I can't find the answer to it anywhere. I want to wrap some existing iOS code that I wrote, in a Appcelerator module. That's it. Important points:
I am NOT wrapping a pre-existing 3rd party iOS SDK.
I wrote the iOS code being wrapped.
Code is verified as working within xcode.
There are no .a files. There are 2x .h files and 2x .m files though.
There are no UI elements in the iOS code as it is only designed to connect the native bluetooth hardware to the app.
I have created a generic appcelerator iOS module project, built it, and successfully called the generic ID function within my app.
I cannot figure out how to successfully edit the generic module so that it utilizes my code. Every attempt results in it refusing to compile, and it's maddening.
I do not have access to Hyperloop.
Once I can successfully build the wrapped module, I would call an initialization function which triggers a native bluetooth hardware search. Once connected, there are functions within the module to send commands to the hardware and receive data back. This is the official documentation I've followed so far:
http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Module_Quick_Start
That helped me build the blank module, include it in the app, and ensure that it worked by calling the built in test property. From there it stops short of actually telling me what I need to know. These are the closest things I've found so far, while still not being what I need:
http://docs.appcelerator.com/platform/latest/#!/guide/iOS_Module_Project-section-43288810_iOSModuleProject-AddaThird-PartyFramework
appcelerator module for existing ios project sdk
Heck, I still don't even know if I can do this within studio or if I have to edit the generic module in Xcode. Help! :) Many thanks in advance.
so first of all, this is not best practice and will cause possible problems in the future when the SDK changes and your module still relies on outdated core API's.
Regarding your question, you could either create a new component that subclasses the existing class, e.g.
class TiMyModuleListViewProxy : TiUiListViewProxy {
}
and call it with
var myList = MyModule.createListView();
or you write a category to extend the existing API with your own logic, e.g.
#interface TiUIListViewProxy (MyListView)
- (void)setSomethingElse:(id)value;
#end
#implementation TiUIListViewProxy (MyListView)
- (void)setSomethingElse:(id)value
{
// Set the value of "somethingElse" now
}
#end
I would prefer the second option since it matches a better Objective-C code-style, but please still be aware of the possible core-changes that might effect your implementation in the feature. Thanks!

No visible #interface for UItableview declares the selector setSeparatorInset

My question is simply the title. I don't understand that if I'm using respondsToSelector why is the code checks for actual implementation ?
I'm on iOS 6, XCode 4.6
I got the answer to my question:
So this has something to do with the theory than iOS or XCode version. Compiler at the time of compilation (of code) checks for the existence of method and since setSeparatorInset is not part of iOS 6.x it will not work b/c compilers don't check for 'if' clauses it simply compiles the code. 'if' clause will be evaluated at runtime. So I'm trying to call the method which isn't there simply BUT what I was trying to achieve is not wrong, it can be done and I can check for method of iOS 7 from code of iOS 6. What I have to do is
[tableView performSelector:#selector()];
This perform selector (is part of tableView) is executed at runtime and I'm not directly calling the method at compile time that's why this will work.

Xcode - turn off debug

Is it possible to turn off debug mode for a specific .m file ?
Summary.
I am writting a framework which will be used in other projects, code contains #try #catch blocks, which handles some exceptions.
Problem.
If framework user turns on Xcode's "All exceptions" breakpoints, then LLDB periodically stops program (when exception is raised) in #try block.
What I want.
I want to mark my framework files "non sensitive" for lldb (ignore exception breakpoints).
Solutions that I have already tried.
I tryed python script which checks eax/r0 and ignores exception, also a variant with breakpoint condition, but all this solutions are not nice for thousand of newbie third party developers.
Is it possible to have some nice solution?
Thanks.
This previous answer demonstrates how you can create a conditional exception breakpoint for your project. It may be a lot of work to specifically exclude each one of your framework's classes.

Resources