我有一个字符串和一个密钥,我想从中生成一个 HMAC SHA256。虽然我使用了 2 个库
IDZSwiftCommonCrypto和CryptoSwift
而这个答案
没有什么对我有用。我的真相来源是这两个网站
和
https://www.freeformatter.com/hmac-generator.html#ad-output
他们总是为我的情况生成正确的哈希键。知道什么可以在这里工作吗?一些代码示例
对于 IDZSwiftCommonCrypto
func getHMacSHA256(forMessage message: String, key: String) -> String? {
let hMacVal = HMAC(algorithm: HMAC.Algorithm.sha256, key: key).update(string: message)?.final()
if let encryptedData = hMacVal {
let decData = NSData(bytes: encryptedData, length: Int(encryptedData.count))
let base64String = decData.base64EncodedString(options: .lineLength64Characters)
print("base64String: \(base64String)")
return base64String
} else {
return nil
}
}
Run Code Online (Sandbox Code Playgroud)
对于 CryptoSwift
let password: Array<UInt8> = Array(payload.utf8)
let salt: Array<UInt8> = Array("somekey".utf8)
let signedBody = try? HKDF(password: …Run Code Online (Sandbox Code Playgroud) 我有一个标签,它从数据库中动态获取一些数据。这些数据是字符串,有时可以是 3-4-5 行等。所以这个标签在 UIView 中。
--UIView
--Label
Run Code Online (Sandbox Code Playgroud)
我怎样才能让UIView标签动态地达到一定的高度??
我有一个滑块的产品,我试图找到每个产品的最低价格.
所以我首先尝试从Controller成功调用一个函数并传递id产品并打印出来.
blade.php
<span class="text-bold">
@php
use App\Http\Controllers\ServiceProvider;
echo ServiceProvider::getLowestPrice($product_cat->id);
@endphp
</span>
Run Code Online (Sandbox Code Playgroud)
路线
Route::post('/getLowestPrice/{id}', 'ServiceProvider@getLowestPrice');
Run Code Online (Sandbox Code Playgroud)
调节器
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ServiceProvider extends Controller
{
public static function getLowestPrice($id) {
return $id;
}
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误
Parse error: syntax error, unexpected 'use' (T_USE)
Run Code Online (Sandbox Code Playgroud)
知道为什么use不在这里工作?
我有一个视图控制器,我希望有以下经验。在视图控制器内部,我有一个按钮,该按钮强制将方向旋转到正确的横向。
在“部署信息-设备方向”中,我启用了“横向右”和“纵向”。
我想提到的是,我在设备中启用了“纵向方向锁定”,这就是为什么我希望按钮使用以下代码以编程方式旋转方向。
let rotateButton: UIButton = {
let btn = UIButton(type: .system)
btn.setTitle("Rotate", for: .normal)
btn.setTitleColor(.red, for: .normal)
btn.addTarget(self, action: #selector(rotateTapped), for: .touchUpInside)
return btn
}()
@objc func rotateTapped() {
let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
}
Run Code Online (Sandbox Code Playgroud)
因此上面的代码可以正常工作,并且屏幕正在旋转。虽然我想在用户旋转回纵向时将屏幕再次旋转至纵向,而无需按下任何按钮。启用“纵向锁定”时,屏幕不会旋转回纵向。
我没有运气尝试过以下代码。
1)
NotificationCenter.default.addObserver(self, selector: #selector(rotated), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
@objc func rotated() {
if UIDevice.current.orientation.isLandscape {
print("Landscape") //when the user taps the button this is being printed.
} else {
print("Portrait") //when the user rotates back to portrait this is …Run Code Online (Sandbox Code Playgroud) 我正试图在UIWebView我加载网站时刷新.代码UIWebView非常简单
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var WebView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let URL = NSURL(string: "https://the url/")
WebView.loadRequest(NSURLRequest(URL: URL!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Run Code Online (Sandbox Code Playgroud)
有没有人有任何例子,因为无论我搜索什么,我只发现了对tableviews的刷新,我不确定它是否也适用于这个.
谢谢.
更新1.在Sohil的建议之后,代码是这样的
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var WebView: UIWebView!
@IBOutlet weak var scrollView: UIScrollView!
override func …Run Code Online (Sandbox Code Playgroud) 我想知道哪个是制作适用于不同iPhone屏幕的iOS 9 swift 2 xcode 7的视图控制器的最佳方法?
我试图用限制来制作它,但是从iphone 4s到iphone 6s屏幕,我们可以看到图标和文本字段等之间存在很大差距.
我的想法是为每个屏幕(5.5英寸,4.7英寸,3.5英寸)制作不同的视图控制器,并让我的应用程序检查用户打开应用程序的屏幕并为此屏幕加载unigue视图控制器.
或者也许有更好的方式,但我是swift 2.0的新手,所以我要求你的帮助!
非常感谢你的时间.
我在我正在构建的网站中的Parse.com Javascript SDK中有这个简单的例子.
课程如下
_User结构:
帖子结构:
OBJECTID
postName - 字符串
postMsg - 字符串
postAuthor - 指针<_User>(指向用户类的指针)
评论结构:
OBJECTID
msg - 字符串
post - 指针<帖子>(指向帖子类的指针)
user - 指针<_User>(指向用户类的指针)
我将此查询发送到评论类,以获取所有评论以及作者姓名和其他一些内容.
var Comments= Parse.Object.extend("Comments");
var query = new Parse.Query(Comments);
/*Get the Post's Info*/
query.include("post");
/*Get the Post Author's Info*/
query.include("post.postAuthor");
/*Get the Comment's Author Info*/
query.include("user");
query.find().then(function(results){
/* Go Through Each Comment*/
var commentsArray = new Array();
for(i in results){
/* Set obj to current comment*/
var …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Swift搜索我的PHP API.直到现在我已经完成了这件事.
var filteredData = [Products]()
func getSearch(completed: @escaping DownloadComplete, searchString: String) {
let parameters: Parameters = [
"action" : "search",
"subaction" : "get",
"product_name" : searchString,
"limit" : "0,30"
]
Alamofire.request(baseurl, method: .get, parameters: parameters).responseJSON { (responseData) -> Void in
if((responseData.result.value) != nil) {
let result = responseData.result
if let dict = result.value as? Dictionary<String, AnyObject>{
if let list = dict["products_in_category"] as? [Dictionary<String, AnyObject>] {
if self.filteredData.isEmpty == false {
self.filteredData.removeAll()
}
for obj in list {
let manPerfumes …Run Code Online (Sandbox Code Playgroud) 我正在试图找出如何在加载后点击网页的某些坐标(比方说x:250px && y:500px).
通过原生点击我的意思是一个真实的生活事件,就像我用我的鼠标点击图像或链接或我想要的任何东西.
无论如何做到了吗?
非常感谢你的时间.
我试图通过Javascript将值从按钮传递到输入值.我现在拥有的是这个
这是一个javascript文件
var test2 = 5;
appendeddatahtml = '<div class="test1"><button id="btn" type="button" value="' + test2 + '">This is it!</button></div>';
$("#test1").append(appendeddatahtml);
Run Code Online (Sandbox Code Playgroud)
这是脚本上方的表单
<input type="text" name="latlon" id="latlon" style="display: none; " value="" />
Run Code Online (Sandbox Code Playgroud)
首先,我尝试使用此代码发出警报
$(document).ready(function() {
$("#btn").click(function() {
alert("The button was clicked.");
});
});
Run Code Online (Sandbox Code Playgroud)
但它没有提醒任何事情.有没有办法将值从按钮传递到输入值?
ios ×5
swift ×5
javascript ×3
jquery ×2
swift2 ×2
swift3 ×2
alamofire ×1
blade ×1
cryptography ×1
cryptoswift ×1
hmac ×1
html ×1
ios11 ×1
ios9 ×1
iphone ×1
laravel ×1
laravel-5 ×1
orientation ×1
php ×1
swift4 ×1
uilabel ×1
uisearchbar ×1
uiview ×1
uiwebview ×1