我正在创建一个检测脚本,当用户到达我的网站时,它会嗅出任何带有视网膜显示器(或类似设备)的设备(目前只有iPhone4).因为分辨率更高,我需要推动更高分辨率的图像/图形.我能找到的唯一解决方案(使用PHP和JavaScript)是检测devicePixelRatio并设置cookie.这是我正在使用的代码:
<?php
$imgPath = "images/";
if(isset($_COOKIE["imgRes"])){
$imgRes = $_COOKIE["imgRes"];
if( $imgRes >= 2 ){
$imgPath = "images/highRes/";
}
} else {
?>
<script language="javascript">
var the_cookie = "imgRes="+window.devicePixelRatio+";"+the_cookie;
document.cookie = the_cookie;
location = '<?=$_SERVER['PHP_SELF']?>';
</script>
<?php
}
?>
Run Code Online (Sandbox Code Playgroud)
有没有人遇到过更好的方法,或者有任何改进此脚本的建议.这个脚本确实有效,只是感觉很脏.
我有一个来自Apple(SquareCam)的示例应用程序,我正在使用它作为参考来为相机创建自定义界面.我正在使用AVFoundation框架.如果我从Apple构建并运行该项目,该应用程序将按预期运行.但是,如果我从该项目中获取相同的代码并将其放在Xcode中的新项目中,则不会显示视频预览.
我已将代码简化为运行视频预览图层的基本组件.同样,这个代码在Apple(SquareCam)项目中运行良好,但不会显示在我的新项目中.
- (void)setupAVCapture {
NSError *error = nil;
AVCaptureSession *session = [AVCaptureSession new];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
[session setSessionPreset:AVCaptureSessionPreset640x480];
else
[session setSessionPreset:AVCaptureSessionPresetPhoto];
// Select a video device, make an input
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *deviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
if ([session canAddInput:deviceInput])
[session addInput:deviceInput];
previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
[previewLayer setBackgroundColor:[[UIColor blackColor] CGColor]];
[previewLayer setVideoGravity:AVLayerVideoGravityResizeAspect];
CALayer *rootLayer = [previewView layer];
[rootLayer setMasksToBounds:YES];
[previewLayer setFrame:[rootLayer bounds]];
[rootLayer addSublayer:previewLayer];
[session startRunning]; …Run Code Online (Sandbox Code Playgroud)
我有一个正在构建的共享(反应)组件库。PrivateRoute我想包含一个组件。但是,当我将组件从模块库导入另一个应用程序时,出现错误:
错误:不变式失败:您不应在<Router>外使用<Redirect>
该PrivateRoute组件react-router/Route使用身份验证逻辑包装该组件,并将未经身份验证的请求重定向到登录:
组件库
import { Route, Redirect } from 'react-router';
/* ... */
class PrivateRoute extends Component {
/* ... */
render() {
const {
component: Comp, authState, loginPath, ...rest
} = this.props;
return (
<Route
{...rest}
render={props => authState === SIGNED_IN ? (
<Comp {...props} />
) : (
<Redirect
to={{
pathname: loginPath,
}}
/>
)}
/>
);
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我将组件导入到一个单独的(反应)项目中:
创建反应应用
import { Router } from 'react-router';
import { PrivateRoute } …Run Code Online (Sandbox Code Playgroud) 当我的页面启动时,setDataOnPage2执行并正常工作.我能够将数据导入$ scope.records以将其呈现给页面.
$scope.setDataOnPage2 = function () {
$http({
method: 'get',
url: GetSchedule,
params: {
date: $scope.currentDate
}
}).success(function (results) {
console.log(JSON.stringify(results));
$scope.records = results;
});
}
$scope.setDataOnPage2();
Run Code Online (Sandbox Code Playgroud)
我的问题是当我使用ng-click从按钮点击此功能.当我单击按钮时,我在JSON演示文稿中看到结果,因为console.log(JSON.stringify(results)),但它是旧数据.
当我打开我的电脑上的表格它工作正常,然后我去我的手机更新数据很好,但当我点击执行setDataOnPage2的刷新按钮时,它在控制台中显示JSON,但不显示更新我在电话上做了,直到刷新页面.我不确定为什么我的http调用缓存了我的数据.
我甚至在后面的代码中放置一个断点,http get应该执行,但它只在页面刷新时执行,而不是在我单击执行setDataOnPage2的刷新按钮时执行.
奇怪的是,json出现在控制台中,但数据没有刷新,也没有达到断点.
关于为什么会发生这种情况的任何想法?
javascript ×2
angularjs ×1
avfoundation ×1
ios ×1
iphone ×1
json ×1
npm ×1
objective-c ×1
php ×1
react-router ×1
reactjs ×1
video ×1
webpack ×1
xcode ×1