localStorage cleared on app restart with Cordova 1.7 and iOS 5.1.1 - ios

From my extensive reading, the iOS 5.1 localStorage/WebSQL behavior change that Apple instituted has been fully rolled into Cordova 1.6.0.
However, while running on my (new) application on Cordova 1.7.0 and iOS 5.1.1, I am still seeing ugly, incorrect behavior.
I use window.localStorage to store and retrieve data. E.g.
window.localStorage.getItem("activeFormId")
window.localStorage.setItem("activeFormId", formId);
These work flawlessly during the same session of the Cordova-based app. If I background the app with the main iOS button then resume, that usually works as well.
However, the moment I kill the application (double-tap, long-press, tap the red circle) and relaunch, all localStorage data is lost. I have verified this with jsconsole.com as well.
Are there additional steps I need to take to ensure the persistence bug fixes are working? Any help is greatly appreciated.

Try using 1.7 - I had a similar issue and once I upgraded to 1.7 everything worked like it used to.
Try using localStorage vs window.localStorage syntax.
Also set what ever you're trying to call as a global variable...
var globalVar;
function onDeviceReady(){
globalVar = localStorage.getItem('something');
}

Related

cdk-virtual-scroll-viewport not working on iOS 15.3 and below Angular 14

Description
After upgrading my Angular application from version 13 to 14, I have noticed that the cdk-virtual-scroll-viewport component no longer works on iOS devices running version 15.3 or earlier. The virtual scrolling feature is not functioning correctly, and the scrolledIndexChange event is not updating as expected. Additionally, the scrollToIndex function is not working on iOS 15.3 or earlier when using Angular 14, although it worked when using Angular 13.
Steps to reproduce
To reproduce the issue:
Create an Angular application with version 14.
Implement the cdk-virtual-scroll-viewport component in the application.
Test the application on an iOS device running version 15.3 or earlier.
Observe that the virtual scrolling functionality is not working correctly, and the scrolledIndexChange event is not updating as expected.
Expected behavior
The cdk-virtual-scroll-viewport component should allow for virtual scrolling on all devices, including iOS devices running version 15.3 or earlier. The scrolledIndexChange event should update correctly as the user scrolls, and the scrollToIndex function should work as expected.
Actual behavior
On iOS devices running version 15.3 or earlier, the virtual scrolling feature is not functioning correctly in the Angular 14 application. The scrolledIndexChange event is not updating, and the scrollToIndex function is not working.
Relevant code
Here is a code sample that I am currently using, which has not been modified since upgrading from Angular 13 to 14:
<cdk-virtual-scroll-viewport #viewPort class="vscroll" *ngIf="categories"
(scrolledIndexChange)="scrolled($event)" customVirtualScrollStrategy [itemHeights]='rowHeights'
[headerHeight]="recommendationHeight">
<section [ngStyle]="{'height.px': rowHeights[i]}"
*cdkVirtualFor="let cat of categories; templateCacheSize: 3; let i = index">
<h1>{{cat.name}}</h1>
</section>
</cdk-virtual-scroll-viewport>
Additional information
I have already attempted to update the #angular/cdk package to the latest version, but the issue persists. I have also checked the documentation and issue tracker for the cdk-virtual-scroll component, but could not find any known issues or workarounds specifically related to iOS 15.3 or earlier. Any assistance with resolving this issue would be greatly appreciated.
Thank you in advance!

MPMediaLibrary.requestAuthorization not responding on Xcode 10.2 simulator

I just noticed that after having updated Xcode to version 10.2.1, I'm unable to see the permission request for Library and Apple Music when launching a couple of projects of mine on the simulator.
Debugging, I realised that the authorization request call goes unanswered
MPMediaLibrary.requestAuthorization { status in
// switch on status and handle it - never gets there
}
I didn't change anything in the code or configuration of my projects, and I'm very sure that this wasn't happening with previous versions of Xcode.
Just for the record, everything works fine on a real device.
Does anybody have any idea?
Am I the only one who's experiencing this?
Looks like it doesn't work on the simulator. It now just hangs, and the closure is never executed.
It did, at one time, but I guess that it no longer does.
Sort of unsurprising, as the basic media capabilities aren't really supported on the simulator anyway.
I have tested my code on device, and verified that it works, but it is annoying (not a showstopper) that it doesn't work on the simulator.

"[Crashlytics:Crash] Reporting is disabled"

I am getting the following error messages when our production iOS app initializes:
[Crashlytics] Version 3.8.4 (121)
[Crashlytics] Running on iOS Simulator (iPhone), 10.3.0 (16E195)
[Crashlytics:Crash] Reporting is disabled
[Crashlytics] Crash reporting could not be initialized
[Answers] Initialized
[Fabric] Initialized with kit versions: {
"com.twitter.answers.ios" = "1.3.4";
"com.twitter.crashlytics.ios" = "3.8.4";
"io.fabric.sdk.ios" = "1.6.11";
}
Every subsequent call to log an event gets the following error:
[Crashlytics:Crash] WARNING: CLSLog has been used before (or concurrently with)
Crashlytics initialization and cannot be recorded. The message was: ...
The non-production versions of the app work fine running the exact same code but with different bundleIDs. Normally when the app initializes for the first time, then I see the app populate in the Fabric dashboard, but in this case the app is not showing up.
We have an Android and an iOS version of the app, and they both use the same bundleID, so I am wondering if there is a conflict because of that? I see the Android version of the app in the dashboard, and it seems to be working properly. This is an app that originally was a Xamarin app that compiled to both platforms, neither of which incorporated Fabric/Crashlytics. We have now written native apps on each platform, and both are using Fabric/Crashlytics.
Since this is a pre-existing app in both stores, we do not have the option of changing either app’s bundleID.
Make sure you initialize Crashlytics with Fabric before calling any Crashlytics methods:
Fabric.with([Crashlytics.self])
One step I routinely miss is to make sure you've added the build phase on your target:
"${PODS_ROOT}/Fabric/run" ${FABRIC_API_KEY} ${FABRIC_BUILD_SECRET}
and either replace ${FABRIC_API_KEY} and ${FABRIC_BUILD_SECRET} with your key and secret or add custom build settings for each.
There are apparently cases where Crashlytics does not auto-activate new apps so that they show up under your list of apps, even though everything is coded correctly and data is going to their servers. In this case, send an email to Crashlytics support (support#fabric.io) that contains a copy of the info.plist entries for the app in question and they will activate it for you. I have had to do this several times, especially with app extensions.
When I finally traced it down in my situation, the error was entirely correct, but not obvious.
I saw these errors in various testing targets where the code we tested was using a custom logging wrapper which called CLSNSLogv(), but the test didn't actually go through the AppDelegate and therefore did NOT initialize Crashlytics. After trying a few things I was convinced that it worked when executed as an app, but in our configuration it was not working under the unit test configuration.
I'll likely alter our custom wrapper to bypass CLSNSLogv() during testing anyway. The biggest benefit of using that is when crashes occur on devices, so we won't be missing anything.

ADAL Cordova Plugin unable to retain token on ios

I'm still a newbie in the mobile app development arena, please forgive me if I did not provide adequate information, probably because my lack of knowledge on its relevance. I'll edit with more info upon request.
Here's what I'm using to build my app on a Windows 7 64bit environment:
AngularJS 1.0
Phonegap Build 6.3.0 (cloud version)
cordova-android 5.2.1 (as shown on Phonegap build)
cordova-ios 4.2.0 (as shown on Phonegap build)
azure-activedirectory-library-for-cordova version 0.7.1
I'm testing on:
Android phone Samsung Galaxy SCH-I545 os version 5.0.1
iPhone 6S Plus os version 9.3.5
Everything went well with Android using ADAL plugin 0.7.1. However on iPhone, it kept going back to the login screen for authentication to our AD FS even though I already got authenticated the first time. I'm suspecting the token did not get stored in cache, that's why acquireTokenAsync kept getting called? I'm still trying to get my hands on a MAC to troubleshoot further.
Then, I updated to ADAL plugin 0.8.0 to see if that might solve my problem, but now Android stopped working and I got this error:
DEVELOPER_AUTHORITY_IS_NOT_VALID_INSTANCE
I debugged through using developer tool on both 0.7.1 and 0.8.0 and I saw no token coming back in acquireTokenAsync method in version 0.8.0. Switching back to 0.7.1 and Android works again.
Could anyone guide me on what might be causing this problem on my iPhone and Android? Maybe I'm missing additional settings or files? The way I updated the ADAL plugin was replacing the cordova-plugin-ms-adal folder under plugins and modify my config.xml file to spec="~0.8.0", that should be sufficient right?
* Update on cordova-android *
I finally got 0.8.0 working on my android device by turning off validateAuthority
var context = new Microsoft.ADAL.AuthenticationContext(authority,false);
I think it's because I'm using AD FS (found this comment in ADErrorCodes.h under adal-for-objc):
/*! The passed in authority URL does not pass validation, if you're trying to use ADFS directly you must disable authority validation. */
/*! An error was raised during the process of validating the authorization authority. */
AD_ERROR_DEVELOPER_AUTHORITY_VALIDATION = 101
* Update on cordova-ios *
Debugging in Safari developer tool, I don't have tokenCacheItems after the native method got called.
bridge.executeNativeMethod('tokenCacheReadItems',[this.authContext.authority, this.authContext.validateAuthority])
.then(function (tokenCacheItems) {
tokenCacheItems.forEach(function (item) {
result.push(new TokenCacheItem(item));
});
d.resolve(result);
}, function(err) {
d.reject(err);
});
I spent almost a week on this already and I really appreciate any help on this issue.

Phonegap iOS 5.1 and localStorage

I was using localstorage for save one value in my App, that works with PhoneGap, but when Apple has released the new iOS 5.1, my App now doesn't save the value.
Does anybody know how to solve this problem?
Thank you very much!!!
Edit: I put the code I was using:
window.localStorage.setItem("login", $('#login').val());
I use it for save the value, and I use it for read the value:
function onDeviceReady() {
var login = window.localStorage.getItem("login");
if (login != null) {
$('#login').val(login);
}
}
But when I close the App, the values are not saved.
There was a large thread in the phonegap group that talked about this problem. Basically its because they now treat localStorage as a temp item which can be deleted at any point. Never fear there are very smart people at work!
here's the thread - https://groups.google.com/forum/?fromgroups#!topic/phonegap/RJC2qA9sDnw
here's the code - http://pastebin.com/5881768B
In iOS 5, localstorage was made persistent by default, by Apple.
In iOS 5.1, localstorage was made a temporary folder that could be deleted by the OS any time storage was constrained.
In iOS 6, localstorage was made an optionally persistent folder with a flag in the setting.
Phonegap 2.0 targeted iOS 5.1 and provided a plugin mechanism to provide persistence even though iOS did not.
With iOS 6 and phonegap 2.1 attempt was made to use the plugin only if the iOS version is 5.1 and fall back to the iOS native mechanism for persisting the folder.
However there is a bug with this fix, on iOS 6, where the localstorage folder gets deleted the first time, the data is stored: https://issues.apache.org/jira/browse/CB-1535
The bug report also has the patch; however it is not yet scheduled to be a part of any of the PhoneGap release version; so you would have to manually apply the patch.

Resources