How to force flutter to use wifi rather than 4G? - dart

My app makes local network calls. Is there a way, with flutter/dart, to force http.get() over WiFi (even if internet is not available) rather than 3G/4G?

Core Flutter framework has not that feature yet(and won't have at least for a long time imo).
When it comes hardware related things, you can almost say that native code is only way to go. Good thing is there many official & third party packages that already done the job for you.
For example this package is popular one for connection related features: https://pub.dev/packages/connectivity
This is the example code you need:
import 'package:connectivity/connectivity.dart';
var connectivityResult = await (Connectivity().checkConnectivity());
if (connectivityResult == ConnectivityResult.mobile) {
// I am connected to a mobile network.
} else if (connectivityResult == ConnectivityResult.wifi) {
// I am connected to a wifi network.
}

There is a plugin that helps you to solve the problem.
You need to add this https://github.com/alternadom/WiFiFlutter plugin to your project like so:
wifi_iot:
git: https://github.com/alternadom/WiFiFlutter.git
and then to force wifi usage you call
WiFiForIoTPlugin.forceWifiUsage(true);
I made it safe and added a platform check
import 'dart:io' show Platform;
if(Platform.isAndroid) {
WiFiForIoTPlugin.forceWifiUsage(true);
}
The downside is, that at the first time you do this in your app, the user will be redirected to allow the app to change system settings (and from there the "back" navigation button doesn't work at the moment).

This is not currently possible with flutter. The only way is to use platform native code via paltform-channels.
https://flutter.dev/docs/development/platform-integration/platform-channels

Related

"Cached element do not exists in DOM" when run Appium with Robot Framework

I'm working on automated test using Appium with Robot framework on Android device. I create schedule run on Jenkins. My test flow is entering some data in page A and submit, then switch to page B to check the result and switch to page A to enter a new data. I repeat this loop for around 10+ time. Everything works fine in around 4-5 rounds but after that there show up an error :
StaleElementReferenceException: Message: Cached element 'By.xpath:
//android.widget.TextView[#text='Limit']' do not exists in DOM anymore
The TextView is in the page A. I monitored the robot and saw that the TextView was shown up but the robot did not see it. I tried restart the device but the problem is not solved. I search through the internet and found some who facing the same issue but they use different programming language like Java or Python. I have no idea what I have to do next.
Development Tools :
Appium version: 1.21.0
Robot Framework version: 4.1.2 (Python 3.10.0 on win32)
First I do not use Robot Framework, but the code should be similar according to this https://robocorp.com/docs/languages-and-frameworks/robot-framework/try-except-finally-exception-catching-and-handling.
Second, I'm not sure if this is the best way to get around this. I think there is something you can do with the expected conditions class to get around this in a "cleaner way" but I'm not quite familiar with it enough to show/tell you. Instead what I've done is something like this...
from selenium.common.exceptions import StaleElementReferenceException
while some_limiting_factor:
try:
# logic for submitting page A, assertions for page B
except StaleElementReferenceException:
element = driver.find_element('By.xpath: //android.widget.TextView[#text='Limit']' )
As much as I want to cache elements in appium, it seems that the service itself does NOT want you to, at least not in my experience. Getting a fresh element(s) every time seems to ensure a "slow but steady" test. Hopefully someone can show me the deep appium secrets one day.

Can I use Zebble for only UI and use Xamarin for everything else

I would like to use Zebble only for producing UI and all other things I would like to use Xamarin apis/custom http apis/local db or whatever it may be. Basically a UI project with zebble and other things will be in PCLs.
Will it be compatible? Could you please advice?
Yes you can. There is nothing in Zebble that prevents you from using the native APIs directly.
For custom http calls, I recommend using the HttpClient class which is by default available in all 3 platforms of a newly created Zebble project.
For Device APIs, you can of course use the standard API classes of each platform, but to save time and achieve 100% code reuse I strongly recommend using the http://zebble.net/docs/device-api. For example if you want o use the lamp (aka flash, led or torch) you can very easily implement that on all platforms with very little code code:
// Determines if a lamp feature is available on the device.
if (await Device.Torch.IsAvailable()) { ... }
// This will switch the lamp on.
await Device.Torch.TurnOn();
// This will switch the lamp off.
await Device.Torch.TurnOff();

How do I demo an electron app on the web

Is there a way to easily distribute an electron.atom.io app as a static site?
I don't need all the functionality, I just want to allow the client to view the latest updates.
-- edit --
Perhaps a better way to ask the question is; "How do I build a web app that can be hosted online and run on electron with minimum rewriting" - similar to the Slack app that works the same way on web or electron app.
As long as your main use of Electron is to create a 'native browser wrapper' for a web-app this is entirely possible.
You will have to implement a check if your application is running inside a browser or inside Electron and wrap your electron specific code in it:
if (window && window.process && process.versions['electron']) {
const {BrowserWindow} = require('electron').remote
}
You'll probably have to step through your application and disable Electron specific functionality at multiple places.
You have other options to do a long distance demo of an Electron app
Electron is basically a shell to run node.js apps on the desktop. This means if you want to move it to the web, you have to give up all the Electron APIs that access the local system and you're left with a basic node.js app, which is most likely not desirable.
To demo your desktop app to an off-site client, you can either make a presentation with screenshots detailing the current user flow, or compile a sandboxed demo version of your app and send it over to them.
Screen presentation
This is your quickest and easiest solution if your client just wants to be kept in the loop and see some eye candy. You can just record how the app works with some example data, add some written or audio explanation to it, and let them enjoy the smooth ride.
Build a demo
If your client wants to actually have a hands-on demo with the app, you need to have some form of basic code distribution. The cleanest way to do this would be to tie up all loose ends in your current app flows, block all unfinished roads in it and compile it for whatever platform your client requested the demo for.
Take a look at the electron-packager and electron-builder docs to get an idea how to build an .exe, .dmg or whatever file from your Electron app, then send that file to them with some basic instructions.

React-Native ios App crashes without report

I'm building an iOS app using React Native and trying to get it testable on phones.
If I plug my phone into the computer and "build" directly to the phone, the app is built correctly and opens/operates correctly, no problem.
But if I try to archive it and send it to phones using iTunes Connect's TestFlight or Fabric with Crashlytics, the app crashes immediately upon opening. It briefly shows the launch screen, but no more.
Moreover, there are no crash reports -- in TestFlight, in Crashlytics, or in XCode, once I plug the phone back in. So I'm operating in the dark here, without any information on what's breaking. Haven't been able to find a similar issue online, so I figured I'd just ask. Any ideas what could be going wrong?
Please let me know if there's any code or other data you might need to see. Some of it's confidential, but I'll try to post an approximate version.
As Chris Geirman suggested, the problem was a JavaScript error. I'm not sure people with similar problems will find this thread, but in case they do, here is the weird error that was occurring.
I had created a simple ORM system, with a BaseModel and a bunch of models that inherited from it. The BaseModel constructor looked like this:
constructor(props = {}, relations = {}) {
Object.keys(props).forEach((k) => {
// Save props to object
this[k] = props[k];
});
this.relations = relations;
this.className = this.constructor.name;
}
That last line was the problem. On my local simulator and if I build the app to my phone by plugging it in, this works fine. As in, if a Message model inherits from BaseModel, calling var msg = new Message(data, relations); msg.className returns Message.
But something about bundling/archiving/sending the app through TestFlight or Fabric.io minifies and uglifies the JavaScript, such that the class names are changed. So instead, if I do this -- var msg = new Message(data, relations); msg.className -- I'll get back a random variable name, something like 't'.
This was a problem in my app, because my home page contained a switch statement that worked off of the className:
iconContent() {
return {
Message: {
icon: <Image style={styles.feedItemIconImage} source={ require('../assets/img/icon_message.png') } />,
color: c.grass
}, ...
}[this.props.className] // from the model item
}
But 'Message' wasn't, as expected, the value of this.props.className -- 't' was. And so, if I were to try to tunnel into, say, the color value, I'd hit an error, because I was trying to access the color property of null.
Why that didn't report, I don't know (I followed Chris's suggestions and installed Sentry, but it still seemed not to report that error).
But that's what was going on. Minification/uglification occurred only when I installed the app on a phone via TestFlight/Fabric, and that's why the app only crashed in those conditions.
Hope this saves anyone running into a similar bug from tearing out their hair.
I'd like to share my own experience of production stage crash, whereas everything worked fine in development stage.
I had the similar problem which caused by the Reactotron logger. Since I'm not bundling it in production stage, a single line of console.tron.log crashed my app with full stealth. (Its kinda my fault, since I didn't give a damn about my linter with 'no-console' setting)
Here's the code snippet I introduce in my root level file, root.js.
if (__DEV__) {
...
console.tron = Reactotron;
...
}
Hope somebody finds this before wasting time figuring out what's wrong.
Not sure if you still have this problem - but if you do, I'd recommend checking out Bugsnag for react native error reporting - which reports crashes in both the JavaScript layer as well as the native layers (java/cocoa).
One of the harder problems to solve in react native crash reporting (as Sasha mentioned) is restoring the original stack traces when using minification and/or obfuscation - this is handled in Bugsnag by providing full support for JS source maps, as well as iOS symbolication and Android Proguard support at the native layers.
Let me know if this helps - I'm a founder # Bugsnag

How to access Safari history from iPhone App using Private Frameworks

I got a situation something like, i can use Private Frameworks of Apple in order to know the operations being performed on iPhone Safari( i.e History the Tabs being browsed and time spend on browsing kind of info).
I have gone through some of the things like Dumping Private frameworks. But i don't know which Framework to Dump i guess WebKit may help.
Can some body please give the needful info to solve this problem.
i have imported the Dumped classes to Frameworks i.e WebHistory.h, WebHistoryItem.h, WebPreferences.h
Please let me know in case i miss anything
#import "WebHistory.h"
- (void)viewDidLoad {
[super viewDidLoad];
WebHistory *history=[WebHistory optionalSharedHistory];
NSLog(#"%#",history);
}
You can't access the Safari History. Apps are sandboxed.
If this is for an in-house app, then you might be able to jailbreak the phones and figure out a way around the sandboxing.
Update:
see this SO link: how-to-access-iphone-safari-history-in-an-app
We can find the history.plist in /var/mobile/Media/Safari/ and this we can read in jailbreaken iPhone.
I think you need a good web developer who will create the web page in such a way so that you can communicate with javascript and get the message you want to get. And for dumping the framework I think you should get with uikit+ webkit framework.
I hacked my framework by using this link - http://aralbalkan.com/2106 I hope this will help to you .

Resources