我有一个应用程序,作为一个普通的应用程序运行,但也有一个NSStausItem.我希望实现在偏好设置中设置复选框的功能,当此复选框打开时,应显示状态项,但是当复选框关闭时,状态项应被删除或不可见.
我在论坛中发现有人遇到类似问题:如何使用复选框打开和关闭菜单栏中的状态项?
但是我对这个解决方案的问题是它没有按预期工作.所以我做了这个复选框,一切正常,但是当我第二次打开应用程序时,应用程序无法识别我在第一次运行时所做的选择.这是因为复选框没有绑定到某个BOOL或某个东西,复选框只有一个IBAction,它在运行时删除或添加状态项.
所以我的问题是:如何在首选项中创建一个复选框,允许我选择状态项是否应该显示.
好吧其实我试过以下我复制了帖子我给你链接
在AppDelegate.h中:
NSStatusItem *item;
NSMenu *menu;
IBOutlet NSButton myStatusItemCheckbox;
Run Code Online (Sandbox Code Playgroud)
然后在Delegate.m中:
- (BOOL)createStatusItem
{
NSStatusBar *bar = [NSStatusBar systemStatusBar];
//Replace NSVariableStatusItemLength with NSSquareStatusItemLength if you
//want the item to be square
item = [bar statusItemWithLength:NSVariableStatusItemLength];
if(!item)
return NO;
//As noted in the docs, the item must be retained as the receiver does not
//retain the item, so otherwise will be deallocated
[item retain];
//Set the properties of the item
[item …Run Code Online (Sandbox Code Playgroud) 我有一个UIImage显示在UIImageView.我还有另一张图像位于UIImageView第一张图像上方.我希望能够仅在第一个图像的边框内拖动第二个图像.为了让我的目标更清晰一点,请看这张图片:http:
//img689.imageshack.us/img689/6136/56308823.png.
绿色引脚应该是可拖动的,但不应该将引脚拖动到蓝色(地图外部).此刻引脚是可拖动的,但我不知道如何检查引脚是否在地图之外.
编辑:我在我的UIImageView子类中使用此方法的可拖动引脚:
- (UIColor *)colorAtPosition:(CGPoint)position {
CGRect sourceRect = CGRectMake(position.x, position.y, 1.f, 1.f);
CGImageRef imageRef = CGImageCreateWithImageInRect([[MapViewController sharedMapViewController]getImage].CGImage, sourceRect);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *buffer = malloc(4);
CGBitmapInfo bitmapInfo = kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big;
CGContextRef context = CGBitmapContextCreate(buffer, 1, 1, 8, 4, colorSpace, bitmapInfo);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context, CGRectMake(0.f, 0.f, 1.f, 1.f), imageRef);
CGImageRelease(imageRef);
CGContextRelease(context);
CGFloat r = buffer[0] / 255.f;
CGFloat g = buffer[1] / 255.f;
CGFloat b = buffer[2] …Run Code Online (Sandbox Code Playgroud) 我UIView根据实际UIKeyboardState(显示/隐藏)移动我的框架.现在我想为此编写一个单元测试(XCTest).基本上我想检查UIView键盘显示与否的框架.
这是我移动的代码UIView,方法通过NSNotification我在以下位置注册的方式触发viewWillAppear:
- (void)keyboardWillShow:(NSNotification *)notification
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[self.view setFrame:CGRectMake(0, -kOFFSET_FOR_KEYBOARD, self.view.frame.size.width, self.view.frame.size.height)];
[UIView commitAnimations];
}
- (void)keyboardWillHide:(NSNotification *)notification
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)
知道单元测试的样子吗?我对单元测试很新,这就是我要问的原因.
是否有可能在eclipse中标记项目的不同类中的多行以供以后编辑,所以我可以编写一些测试代码,然后在我发布我的软件之前,我有可能显示所有标记的行并删除或编辑它们?
我知道eclipse中的任务只是不确定这是否是正确的方法,因为我必须每次输入任务的名称,并且就我所知,没有可能将它们组合在一起.
我需要使用我的应用程序获取15个最近用户的列表.当前用户的当前位置存储如下:
PFGeoPoint *currentLocation = [PFGeoPoint geoPointWithLocation:newLocation];
PFUser *currentUser = [PFUser currentUser];
[currentUser setObject:currentLocation forKey:@"location"];
[currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error)
{
NSLog(@"Saved Users Location");
}
}];
Run Code Online (Sandbox Code Playgroud)
现在我想通过PFQuery检索附近的用户,如下所示:
- (NSArray *)findUsersNearby:(CLLocation *)location
{
PFGeoPoint *currentLocation = [PFGeoPoint geoPointWithLocation:location];
PFQuery *locationQuery = [PFQuery queryWithClassName:@"User"];
[locationQuery whereKey:@"location" nearGeoPoint:currentLocation withinKilometers:1.0];
locationQuery.limit = 15;
NSArray *nearbyUsers = [locationQuery findObjects];
return nearbyUsers;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是它不起作用.我的阵列似乎没有条目.有人可以为我清理一下,如何正确使用查询?
干杯,大卫
(也发布于:https://www.parse.com/questions/pfquery-to-retrieve-users-nearby)
我目前正在使用Vapor开发Swift后端。我的iOS客户端使用新的iOS 13功能“使用Apple登录”。当用户登录时,我得到一个身份令牌(访问令牌),它是Apple签名的有效JWT令牌。这将在所有正在进行的通信中发送到服务器,以验证服务器提供的某些路由。
在服务器上,我想验证发送的令牌确实由Apple签名,并且不是某些恶意用户通过验证令牌签名专门制作的。Apple提供了一个HTTP端点来检索执行此操作的公共密钥:Apple文档。
但是,我不确定必须多久查询一次此端点以从API检索模数和指数并构建公钥,然后验证签名。是否足以查询一次并在服务器上存储公用密钥以使用它,还是我需要在验证签名(针对每个受保护的路由)之前查询中间件中的HTTP端点?
基本上我不确定模数和指数是否会不时变化。
我有NSStatusItem与自定义NSView显示图像.无论菜单是否打开,它都会显示不同的图像:
isMenuVisible = NO;
- (void)awakeFromNib {
statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[statusItem retain];
dragStatusView = [[DragStatusView alloc] init];
[dragStatusView retain];
dragStatusView.statusItem = statusItem;
[dragStatusView setMenu:statusMenu];
[dragStatusView setToolTip:NSLocalizedString(@"Menubar Countdown",
@"Status Item Tooltip")];
[statusItem setView:dragStatusView];
[dragStatusView setTitle:@"11"];
}
- (void)drawImage:(NSImage *)aImage centeredInRect:(NSRect)aRect{
NSRect imageRect = NSMakeRect((CGFloat)round(aRect.size.width*0.5f-aImage.size.width*0.5f),
(CGFloat)round(aRect.size.height*0.5f-aImage.size.height*0.5f),
aImage.size.width,
aImage.size.height);
[aImage drawInRect:imageRect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f];
}
- (void)drawRect:(NSRect)rect {
// Draw status bar background, highlighted if menu is showing
[statusItem drawStatusBarBackgroundInRect:[self bounds]
withHighlight:isMenuVisible];
if(isMenuVisible) {
[self drawImage:image2 centeredInRect:rect];
}else {
[self drawImage:image1 …Run Code Online (Sandbox Code Playgroud) 我有一个PHP脚本,应该发送邮件给多个收件人.我想把所有收件人都写到BCC.电子邮件地址是从mysql数据库中检索的.不幸的是它不会发送任何邮件.
这是脚本:
<?php
include("/path/to/config.php");
$db = @new mysqli($mysql_host, $mysql_user, $mysql_pass, $mysql_db);
if (mysqli_connect_errno()) {
die ('Konnte keine Verbindung zur Datenbank aufbauen: '.mysqli_connect_error().'('.mysqli_connect_errno().')');
}
$sql = "select email from newsletter";
$recipients = array();
$result = $db->query($sql);
if (!$result) {
printf("Query failed: %s\n", $mysqli->error);
exit;
}
while($row = $result->fetch_row()) {
$recipients[]=$row;
}
print_r($recipients);
$result->close();
$db->close();
$to = 'myemail';
$subject = $_POST["subject"];
$body = $_POST["message"];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'Reply-To: support@mymail.de' . …Run Code Online (Sandbox Code Playgroud) ios ×4
cocoa ×2
nsstatusitem ×2
objective-c ×2
arrays ×1
eclipse ×1
eclipse-juno ×1
email ×1
ide ×1
implode ×1
iphone ×1
jwt ×1
menubar ×1
mysql ×1
nsstatusbar ×1
nsview ×1
pfquery ×1
php ×1
rsa ×1
swift ×1
tags ×1
uiimage ×1
uiimageview ×1
uitouch ×1
uiview ×1
unit-testing ×1
vapor ×1
xctest ×1