在iOS9中,我们提示用户是否需要通知并将其引导至设置页面,以便他们可以为我们的应用启用通知权限.但是,如下所示,没有选项可以在iOS 10中的我的应用程序权限设置中启用通知.是否有一个新进程,我必须使用适当的权限填充此列表?
码
//check the notifications status. First the global settings of the device, then our stored settings
func checkGlobalNotifications() {
let grantedSettings = UIApplication.sharedApplication().currentUserNotificationSettings()
if grantedSettings!.types.rawValue & UIUserNotificationType.Alert.rawValue != 0 {
globalNotificationsEnabled = true
//if global notifications are on, then check our stored settings (user)
if CallIn.Settings.notificationsEnabled { notificationsOn() } else { notificationsOff() }
}
else {
globalNotificationsEnabled = false
//global notifications (iOS) not allowed by the user so disable them
notificationsOff()
}
}
Run Code Online (Sandbox Code Playgroud) 添加这行代码会导致编译时间从10秒增加到3分钟.
var resultsArray = hashTagParticipantCodes + prefixParticipantCodes + asterixParticipantCodes + attPrefixParticipantCodes + attURLParticipantCodes
Run Code Online (Sandbox Code Playgroud)
将其更改为此会使编译时间恢复正常.
var resultsArray = hashTagParticipantCodes
resultsArray += prefixParticipantCodes
resultsArray += asterixParticipantCodes
resultsArray += attPrefixParticipantCodes
resultsArray += attURLParticipantCodes
Run Code Online (Sandbox Code Playgroud)
为什么第一行导致我的编译时间如此急剧减慢并且有一种更优雅的方式来合并这些数组而不是我发布的5行解决方案?
我可以使用动态编程以正确的方式执行此操作,但我无法弄清楚如何在指数时间内执行此操作.
我正在寻找两个字符串之间最大的公共子序列.注意:我的意思是子序列而不是子串,构成序列的符号不必是连续的.
我很清楚这个问题已被问到,但我找不到有效的答案.使用先前解决方案的组合我已经提出了这个代码:
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)string
{
int numLines = notesTextView.contentSize.height / notesTextView.font.lineHeight;
if (numLines <= 8)
{
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为行数在附加文本之前计算,因此我们仍然超出我们想要的行,然后被捕获,因为无法进一步编辑.
我也尝试过检测"\n"条目的解决方案,但这不起作用,因为我们可以自然地到达新行而不按返回.
现在我使用上面的代码将可选项设置为空字符串(如果它是nil)并且如果它具有值则将其解包.这只是三行代码,但对我来说这是一个非常常见的操作,所以我想知道是否有更优雅的方法来做到这一点?
var notesUnwrapped:String = ""
if(calendarEvent.notes != nil){
notesUnwrapped = calendarEvent.notes!
}
Run Code Online (Sandbox Code Playgroud) 是否可以像这样同时使用可选链接和零合并?
\n\nprint("Meeting host: " + meeting.host?.email ?? \xe2\x80\x9cNo host\xe2\x80\x9d)\nRun Code Online (Sandbox Code Playgroud)\n\n我想这样做,但我收到一条错误消息,说我的字符串?没有打开。email是一个非可选字符串。
这是否可以在无需host事先打开包装的情况下实现?如果不是,为什么我的尝试不起作用?
可能重复:
android:如何优雅地设置许多按钮ID
这是一个用eclipse制作的android程序.我尝试在imageButton1的位置使用字符串连接无效.R是生成的类,所以我不能进入它并编辑它,以便imageButtons是数组的一部分.如何将其置于for循环中?
seatButton[0] = (ImageButton) findViewById(R.id.imageButton1);
seatButton[1] = (ImageButton) findViewById(R.id.imageButton2);
seatButton[2] = (ImageButton) findViewById(R.id.imageButton3);
seatButton[3] = (ImageButton) findViewById(R.id.imageButton4);
seatButton[4] = (ImageButton) findViewById(R.id.imageButton5);
seatButton[5] = (ImageButton) findViewById(R.id.imageButton6);
seatButton[6] = (ImageButton) findViewById(R.id.imageButton7);
seatButton[7] = (ImageButton) findViewById(R.id.imageButton8);
seatButton[8] = (ImageButton) findViewById(R.id.imageButton9);
seatButton[9] = (ImageButton) findViewById(R.id.imageButton10);
Run Code Online (Sandbox Code Playgroud) 重新安装我的应用程序后,尽管我的SharedPreferences条目尚未创建,但仍在访问我的if语句中的代码.我正在使用带有eclipse的模拟器,是否需要以重新安装的方式清除数据?谢谢
prefs = getSharedPreferences("appData", 0);
Gson gson = new Gson();
String gsonStr = prefs.getString("playerString", null);
if(gsonStr != null)
{
//This code is being accessed on the apps first onCreate() call prior to being reinstalled
Player[] tempArray = gson.fromJson(gsonStr, Player[].class);
Log.d("First Player", "" + tempArray[0]);
}
protected void onPause()
{
super.onPause();
if(savedPlayers != null)
{
Gson gson = new Gson();
String gsonStr = gson.toJson(savedPlayers.toArray());
prefs = getSharedPreferences("appData", 0);
SharedPreferences.Editor editor = prefs.edit();
//editor().clear();
Log.d("GSONString",gson.toString());
editor.putString("playerString", gsonStr);
editor.putInt("ArraySize", savedPlayers.size());
editor.commit();
}
}
Run Code Online (Sandbox Code Playgroud) 我已经创建了一个计算的静态属性,我希望它计算一次,之后无论何时访问都只会返回原始计算值。lazy属性似乎是我想要的,但经过一些搜索后lazy,默认情况下似乎静态属性。
当我运行以下代码时,第一次访问它时/如果我单独运行每个单元测试,它会很好。但是,当我第二次访问它时,我得到了一个空数组。
static var att: [ConferenceNumber] = {
let list = buildDirectory(for: .att, from: jsonArray)
return list
}()
private static let jsonArray: [Any]? = {
let numbersFilePath = Bundle.main.path(forResource: "numbers", ofType:"json")
let data = try! Data(contentsOf: URL(fileURLWithPath:numbersFilePath!), options: .uncached)
return try! JSONSerialization.jsonObject(with: data) as? [Any]
}()
Run Code Online (Sandbox Code Playgroud)
第 2 次调用并返回空数组的代码
private static func isAttMeeting(meetingText: String, parsedPhoneNumbers: [String]) -> Bool {
let attPhoneNumbers = ConferenceNumberDirectory.att.map{$0.number}
let attNumberWasParsed = parsedPhoneNumbers.intersects(with: attPhoneNumbers)
if attNumberWasParsed {
return true
}
return meetingText.contains(pattern: …Run Code Online (Sandbox Code Playgroud) 我的程序目前有三十个UILabel,可能包含一到三位数字.我想让我的UILabels水平扩展和收缩,因为它们中的数字会改变大小.目前文本正在缩小,UILabels的大小保持不变.
如果只使用xib文件可以做到这一点,那么以编程方式执行此操作会更好,但如果不可能,那么这将是很好的.
谢谢
我的目标C非常生疏,真的不记得如何在创建时在自定义类中启动变量.
所有错误(id)init:
*缺少类型说明符,默认为'int'(警告)
*类型名称需要说明符或限定符
*预期';' 在声明清单的最后
#import "Seat.h"
@implementation Seat
{
(id)init
{
self = [super init];
player = NULL;
position = -1;
state = "empty";
}
}
@end
Run Code Online (Sandbox Code Playgroud)
对不起,如果这看起来很简单,它看起来很简单,我找不到太多.谢谢
ios ×6
swift ×5
objective-c ×3
android ×2
java ×2
algorithm ×1
arrays ×1
big-o ×1
compilation ×1
eclipse ×1
exponential ×1
for-loop ×1
ios10 ×1
iphone ×1
option-type ×1
optional ×1
pseudocode ×1
r.java-file ×1
sequence ×1
swift2 ×1
uilabel ×1
uitextview ×1
xcode ×1