Xamarin Android app can't parse Android.Graphics.Color in release mode, but in debug mode everything works as expected - firebase-realtime-database

For some reason, FirebaseClient (FirebaseDatabase.net) in release mode can't parse Android.Graphics.Color objects which are part of my data class, but in debug mode it works without problem.
Firebase observer for Table:
private readonly FirebaseClient firebaseClient = new FirebaseClient(...);
...
firebaseClient.Child("Tables")
                          .AsObservable<Table>()
                          .Subscribe(d =>
                          {
                              if (d.Object != null)
                              {
                                  Table table = d.Object;
                                  // ...
                              }
                          });
Table class
public class Table
{
        public int Id { get; set; }
        public byte SeatsNum { get; set; }
        public List<Guest> Guests { get; set; }
        [JsonConstructor]
        public Table(int id, byte seatsNum)
        {
            Id = id;
            SeatsNum = seatsNum;
            Guests = new List<Guest>();
        }
        public Table(int id, byte seatsNum, List<Guest> guests)
        {
            Id = id;
            SeatsNum = seatsNum;
            Guests = guests ?? new List<Guest>();
        }
}
Guest class
public class Guest
{
        public string Name { get; }
        public Color  BackgroundColor { get; }
        public Color TextColor { get; }
        public List<string> Tags { get; }
        public int TableId { get; }
        public bool Checked { get; set; }
        public Guest(string name, int tableId)
        {
            Name = name;
            ColorService colorService = new ColorService();
            (Color backgroundColor, Color textColor) = colorService.GetRandomColor();
            BackgroundColor = backgroundColor;
            TextColor = textColor;
            Tags = new List<string>();
            TableId = tableId;
            Checked = false;
        }
        public Guest(string name, int tableId, params string[] tags)
            : this(name, tableId)
        {
            Tags = tags.ToList();
        }
        [JsonConstructor]
        public Guest(Color backgroundColor, bool Checked, string name, int tableId, List<string> tags, Color textColor)
        {
            Name = name;
            BackgroundColor = backgroundColor;
            TextColor = textColor;
            Tags = tags ?? new List<string>();
            TableId = tableId;
            this.Checked = Checked;
        }
}
In debug mode everything works fine, but when i switch app to release mode and rebuild project, for some reason Color objects are (R,G,B,A)=(0,0,0,0), all other properties of data classes are parsed successfully.
I have solved my problem by saving BackgroundColor and TextColor as strings and manually convert them in Color object when needed.
But, im interested, what could be a problem that can lead from normal behavior in debug mode to failure in release mode?

You can check this doc(Configure the Linker).
The linker then discards all the unused assemblies, types, and members that are not used (or referenced).
It could cause some helpful assemblies to be ignored when in release mode.

Related

Changing Firebase configuration at runtime on iOS

For my project, I have 2 environments:
test
prod
and 2 localizations:
en
tr
and an app for each combination: (these names do not mirror Firebase project ids)
test_en
test_tr
prod_en
prod_tr
And I have a separate plist file for each of these apps in the project, with the names Firebase-(app_type).plist ie Firebase-test_en.plist or Firebase-prod_en.plist
I am initializing FIRApp using this way:
private func ensureLoaded() {
let options = FIROptions(contentsOfFile: Bundle.main
.path(forResource: "Firebase-\(firebaseApplicationName)", ofType: "plist"))!
if nil == FIRApp(named: firebaseApplicationName) {
FIRApp.configure(withName: firebaseApplicationName, options: options)
}
}
And it seems to work ok, until I try to actually connect to firebase database, where it says:
Firebase is not configured correctly, please call [FIRApp configure]
So my question is, how do I make firebase work where I want to dynamically change configurations? There are some other questions that describe how to change configuration based on some environment variables / compiler flags but they are all referring to changing the plist file, which changes the configuration during build time, but I want to change it dynamically during runtime. Is it supported at all, is there a way to make it work?
Thanks in advance.
I found what the problem was, we were using FIRApp.auth().currentUser somewhere in the app, which returns the auth for "default" app and since we had multiple configs, we had no notion of a "default" app, so the configuration was incomplete. I changed that to FIRAuth(app: myApp)?.currentUser and it works as expected now.

Turning camera off in fine-uploader on iOS

I'm very new to fine-uploader; I hope my question is relevant...
I'm trying to disable the camera for users of our Web App on iPad and iPhone only (iOS), both for Safari and Chrome. I have tried setting the option camera: {ios: false} but the camera option still shows in Safari and Chrome. When I use workarounds: { ios8BrowserCrash: true}, the camera option does disappear in Chrome but still shows in Safari. What am I missing?
We are using fine-uploader 5.1.2, I briefly tried 5.2.2 with the same results. The app is HTML5, Javascript, Angular with Java back-end. I have tested on iPad with iOS 8.3, 8.4 and 9 beta.
As an aside, the reason I'm trying to disable the camera is due to iOS often crashing when loading the image from the camera. I have found the application crashing a lot less when loading from the device image library, bypassing the camera. Is that a known issue with iPad/iPhones?
Thanks in advance for the help.
Thanks #Ray. For reference, I'm now using the latest FineUploader version 5.3.0.
As you suggested the multiple attribute was being removed. I traced it to the input.removeAttribute("multiple"); code below (s3.fine-uploader.js):
setMultiple: function(isMultiple, optInput) {
var input = optInput || this.getInput();
// Temporary workaround for bug in in iOS8 UIWebView that causes the browser to crash
// before the file chooser appears if the file input doesn't contain a multiple attribute.
// See #1283.
if (options.ios8BrowserCrashWorkaround && qq.ios8() && (qq.iosChrome() || qq.iosSafariWebView())) {
input.setAttribute("multiple", "");
}
else {
if (isMultiple) {
input.setAttribute("multiple", "");
}
else {
input.removeAttribute("multiple");
}
}
},
Despite options.ios8BrowserCrashWorkaround being set to true in my code (ios8BrowserCrash: true), the program was still going through to removeAttribute("multiple") line of code when running on IPad/Safari.
After several tries and errors I found out that (possibly...) the library code was missing testing for the condition qq.iosSafari()on an iPad (iOS 8.3) ; the qq.iosSafariWebView() test isn't sufficient to detect the Safari browser on my iPad, therefore missing the code where the multiple attribute is set.
I found out that the following options values in my calling code fixed the issue.
function initialiseS3() {
uploader = new qq.s3.FineUploader({
element: $element[0],
template: $(contents)[0],
debug: false,
// iosEmptyVideos workaround must be false to enable FineUploader to keep multiple:true in iOS
workarounds: {
iosEmptyVideos: false,
ios8BrowserCrash: true
},
// Must add the test qq.iosSafari() to set multiple to true and have the camera turned off on iPad
multiple: qq.ios8() && (qq.iosSafari() || qq.iosChrome() || qq.iosSafariWebView()) ? true : false,
camera: {
ios: false
},
… (more initialisations)
`
The last catch was to override the default value for the workaround option iosEmptyVideos and set it to iosEmptyVideos: false to avoid the library forcing multiple to false again. I hope this makes sense…

session Storage not working in device

I'm keeping in session one json array, the evidence that I do in the browser function without problem but when I try to test them on devices (iOS or Android) does not hold anything, I am using AngularJS + ionic. With this function I keep everything:
.factory('sessionService',['$http',function($http){
return {
set:function(key,value){
return sessionStorage.setItem(key,JSON.stringify(value));
},
get:function(key){
return JSON.parse(sessionStorage.getItem(key));
},
destroy:function(key){
return sessionStorage.removeItem(key);
},
};
}])
I think you should use localStorage.Test if the values are overwritten or deleted after app restart on device (specially for iOS), anyway.

Core data auto migration is not working

Folks,
I need some help on core data migration and here is the description about situation.
I have a existing iOS app which is using core data for offline support.
Current version of the app in the store is 1.1 and current version of core data model in the app store is 11 (Model11.xcdatamodel).
Now I am releasing a new version (1.1.1) to the app store and there are major works have happened. Also one of the entity has got a new attribute added in core data.
Before making changes to model file, I added new model file (Model12.xcdatamodel) by keeping Model11.xcdatamodel as a base.
Made Model12.xcdatamodel as a current version.
Added new attribute in one of the entity to support on of the feature, made changes in mode etc.
After this I made Model11.xcdatamodel whose type as "version core data model" from Xcode utility window (right side).
Installed 1.1v from app store, did login and on top of this I created 1.1.1v app in release mode and installed.
But app starts crashing and it says the store URL is empty, here is the log from device.
Jan 19 13:04:50 iPod MyApp[15856] <Error>: Magical Record Stack: Current Default Core Data Stack: ----
Model: {
BroadcastMessage = <6fa959c6 514f4c53 e53e7fd7 28585c56 6d4da4ad ba56c2c4 d92bef6e debadfd4>;
Data = <92870bec c4a8794e 293dcbe9 93282d69 cb675039 cb9b9bf6 8dda6359 34697663>;
Event = <de060947 8ec9f2bb 80e341eb 787e7eec 7cc2a09f 356e511c 7d515ca5 130690fe>;
InvitedFriend = <1e041915 6931f26e fd325666 299adf13 5fa2a735 b16b5faf cc0c7de1 1792c97f>;
MAnswer = <5c06b689 b0497f14 65e550d0 1bd30779 08056f42 a6361f71 4e0eb2e5 67127d66>;
MQuestion = <96d6e2a6 b96f1371 2c52e719 ca6a0cbd 7957e63a 4a6ccbe8 049e8818 f9ec5d2d>;
MUser = <af239067 1b3fb3d9 d63b6536 e0e411a8 6ff5f02e db5d7c01 968a4835 4f361610>;
NotificationSettings = <75be9f25 cfb5f63e 9f717160 9b389386 8fb9d7e2 093648ac beff79dd b0c8181b>;
RecentContact = <0eaf2696 94c73a4e 9155b3aa c98bf623 51165db6 c1a1472c 2178c3d0 654c0dac>;
}
Coordinator: <NSPersistentStoreCoordinator: 0x15e883a0>
Store: (null)
Default Context: <NSManagedObjectContext (0x15e96c70): *** DEFAULT ***> on *** MAIN THREAD ***
Context Chain:
- DEFAULT (0x15e96c70) (*)
- BACKGROUND SAVING (ROOT) (0x15e99000)
Jan 19 13:04:50 SB-iPod Medusa[15856] <Error>: Store2 URL after creation (null)
store URL is coming as NULL. I am not sure why this is happening.
I get a valid URL if I run in the debug mode and note that I am using Magical Records for core data.
I have followed what is mentioned in this link https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreData/Articles/cdUsingMOM.html
But this is not working
Can some tell me why this migration is getting failed and how can I fix this?
Finally I ended up in using manual migration and not auto/light migration. This solved the problem
Pls check this link which is very useful https://github.com/magicalpanda/MagicalRecord/issues/466

MonoTouch JIT Error in Release mode on Linq Method

I currently have some code as shown below that uses Linq to organize some IEnumerables for me. When executing this code on the device in release mode (iOS 5.0.1, MonoTouch 5.0.1, Mono 2.10.6.1) I get the exception
Attempting to JIT compile method 'System.Linq.OrderedEnumerable`1:GetEnumerator()' while running with --aot-only.
The code that generates this error is
// List<IncidentDocument> documents is passed in
List<LibraryTableViewItemGroup> groups = new List<LibraryTableViewItemGroup>();
List<DocumentObjectType> categories = documents.Select(d=>d.Type).Distinct().OrderBy(s=>s.ToString()).ToList();
foreach(DocumentObjectType cat in categories)
{
List<IncidentDocument> catDocs = documents.Where(d => d.Type == cat).OrderBy(d => d.Name).ToList();
List<LibraryTableViewItem> catDocsTableItems = catDocs.ConvertAll(d => { return new LibraryTableViewItem{ Image = GetImageForDocument(d.Type), Title = d.Name, SubTitle = d.Description}; });
LibraryTableViewItemGroup catGroup = new LibraryTableViewItemGroup{ Name = GetCatName(cat), Footer = null, Items = catDocsTableItems };
groups.Add (catGroup);
}
This error doesn't happen in the simulator for Release|Debug configurations, or on the device for the Debug configuration. I've seen a couple of similar threads on SO here and here, but I'm not sure I understand how they apply to me on this particular issue.
It could be a few things.
There are some limitations when using full AOT to build iOS applications, i.e. ensuring that nothing will be JITted at runtime (an Apple restriction). Each one is different even if the message looks identical (i.e. many causes will lead to this). However there are generally easy workarounds we can suggest for them;
It could also be a (known) regression in 5.0.1 (which is fixed in 5.0.2). This produced a few extra AOT failures that are normally not issues (or already fixed issues).
I suggest you to update to MonoTouch 5.0.2 to see if it compiles correctly your application. If not then please fill a bug report on http;//bugzilla.xamarin.com and include a small, self-contained, test case to duplicate the issue (the above is not complete enough). It seems an interesting test case if it works when debugging is enabled.

Resources