我在尝试将 SharedPreference 注入 ViewModel 时遇到问题,我正在使用 dagger 进行依赖项注入。我将添加下面代码的主要部分
模块 SharedPreferencesModule.java
@Module
public class SharedPreferencesModule {
private Context context;
public SharedPreferencesModule(Context context) {
this.context = context;
}
@Provides
public SharedPreferences provideSharedPreferences() {
return this.context.getSharedPreferences("login",Context.MODE_PRIVATE);
}
}
Run Code Online (Sandbox Code Playgroud)
添加子组件如下所示
@DashScope
@ContributesAndroidInjector(
modules = {
DashboardFragmentBuildersModule.class, D
ashboardViewModelsModule.class,
DashboardModule.class,
SharedPreferencesModule.class // Added Newly for injecting
}
)
abstract DashboardActivity contibuteDashboardActivity();
Run Code Online (Sandbox Code Playgroud)
我收到的错误如下
错误:@Subcomponent.Factory 方法缺少所需模块或子组件的参数:
我知道 SharedPreferencesModule 中的构造函数导致了错误,并且由于该模块是使用 ContributesAndroidInjector 添加的,因此我无法将上下文传递给 SharedPreferencesModule。但我需要它来获取 SharedPreferences
有什么办法可以摆脱这个问题吗?
我的 BaseApplication 代码如下
public class BaseApplication extends DaggerApplication {
@Override
protected AndroidInjector<? extends DaggerApplication> …Run Code Online (Sandbox Code Playgroud) android dependency-injection viewmodel sharedpreferences dagger-2
我有一个在 php 上运行的应用程序,其中使用下面的代码使用 openssl encrption 加密了一些值
<?php
define('OSSLENCKEY','14E2E2D1582A36172AE401CB826003C1');
define('OSSLIVKEY', '747E314D23DBC624E971EE59A0BA6D28');
function encryptString($data) {
$encrypt_method = "AES-256-CBC";
$key = hash('sha256', OSSLENCKEY);
$iv = substr(hash('sha256', OSSLIVKEY), 0, 16);
$output = openssl_encrypt($data, $encrypt_method, $key, 0, $iv);
$output = base64_encode($output);
return $output;
}
function decryptString($data){
$encrypt_method = "AES-256-CBC";
$key = hash('sha256', OSSLENCKEY);
$iv = substr(hash('sha256', OSSLIVKEY), 0, 16);
$output = openssl_decrypt(base64_decode($data), $encrypt_method, $key, 0, $iv);
return $output;
}
echo encryptString("Hello World");
echo "<br>";
echo decryptString("MTZHaEoxb0JYV0dzNnptbEI2UXlPUT09");
?>
Run Code Online (Sandbox Code Playgroud)
我有另一个在 nodejs 上运行的端点,我需要根据上面的 php 加密/解密规则来解密和加密值。我已经搜索过但找不到解决方案。
我尝试使用该库crypto但最终出现错误 …
我需要在我的闪屏上使用全屏图像来使用 React Native 构建 IOS 应用程序。我已经提交了不同的帖子,但他们中的大多数人都解释了中心带有徽标的 spash 屏幕,但没有人对适合所有设备分辨率(包括 iPad)的全屏 splah 图像给出正确的解释。
我已经创建了一个带有视图和图像视图的 LaunchScreen.xib 文件,如下所示,但它在 iPad 中损坏,但它在某种程度上适合 iPhone(虽然它也有一些黑色阴影用于高分辨率 iphone)
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="15400" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina5_5" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15404"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleAspectFit" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="414" height="716"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView …Run Code Online (Sandbox Code Playgroud) 我想console.warn用一行代码删除和所有其他出现在我的本机应用程序上的警告消息。在我通过在App.js 中添加以下内容来实现之前
console.disableYellowBox = true;
Run Code Online (Sandbox Code Playgroud)
但不知何故它现在不起作用,代码仍然存在于我的App.js 中,但黄色框上的警告仍然显示在屏幕底部。由于我的应用程序很大,它使用了几个包,而且我还在console.warn很多地方添加了,我需要一个解决方案来从一个地方禁用它
有人请帮我找出为什么console.disableYellowBox = true;不起作用,或者请提供一些替代解决方案来解决这个问题。
我的本机版本是 0.60.5
任何帮助将非常感激。
提前致谢
我有一个数组
FruitsList = [
{name: 'apple', color: 'red'},
{name: 'grapes', color: 'violet'},
{name:'avocado', color: 'green'}
]
Run Code Online (Sandbox Code Playgroud)
接下来我想填充另一个对象数组
Food = [{fruitName: '', fruitColor:''}]
Run Code Online (Sandbox Code Playgroud)
来自前一个数组的所有值。我尝试过映射但失败了。谁能帮助我使用 Javascript 或 Typescript 中的哪种方法?
android ×2
react-native ×2
arrays ×1
console ×1
dagger-2 ×1
encryption ×1
ios ×1
ipad ×1
javascript ×1
node-crypto ×1
node.js ×1
object ×1
openssl ×1
php ×1
reactjs ×1
viewmodel ×1
xcode ×1