我有一个实现的视图控制器CLLocationManagerDelegate.我创建了一个CLLocationManager变量:
let locationManager = CLLocationManager()
Run Code Online (Sandbox Code Playgroud)
然后在viewDidLoad,我设置属性:
// Set location manager properties
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
locationManager.distanceFilter = 50
Run Code Online (Sandbox Code Playgroud)
问题是,即使在我检查授权状态之前,函数也会被调用.
func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
if (status == .AuthorizedWhenInUse) {
// User has granted autorization to location, get location
locationManager.startUpdatingLocation()
}
}
Run Code Online (Sandbox Code Playgroud)
谁能告诉我可能导致这种情况发生的原因?
我见过其他人遇到过这个问题,但没有一个帖子可以帮助我.我正在尝试将Volley用于我的REST调用库,当我尝试使用带有JSON对象的Put调用作为参数时,我得到了error with: org.json.JSONException: End of input at character 0 of.
这是代码:
protected void updateClientDeviceStatus(Activity activity, final int status) {
JSONObject jsonParams = new JSONObject();
try {
jsonParams.put("statusId", String.valueOf(status));
} catch (JSONException e1) {
e1.printStackTrace();
}
Log.i(LOG_TAG, "json: " + jsonParams.toString());
String url = Constants.API_URL + "client/device/" + getDeviceId();
// Request a response from the provided URL.
JsonObjectRequest request = new JsonObjectRequest
(Request.Method.PUT, url, jsonParams, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i(LOG_TAG, "updated client status");
Log.i(LOG_TAG, …Run Code Online (Sandbox Code Playgroud) 我在导航栏中有一个条形按钮项,按下时将显示一个UIAlertController样式为.ActionSheet.在iPhone中,它看起来就像我想要的那样.对于iPad,我知道我需要添加
// For iPad, set the pop over bounds
var popOver = optionMenu.popoverPresentationController
popOver?.sourceView = button as UIView
popOver?.sourceRect = (button as UIView).bounds
popOver?.permittedArrowDirections = UIPopoverArrowDirection.Any
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何使用条形按钮项目作为sourceView和sourceRect?我希望popover指向bar按钮项.
我inputView为我创建了一个自定义UITextField.视图本身外观和功能都很棒,但在iPad上我会在我的自定义上方获得撤消,重做和粘贴按钮inputView.如何删除这些按钮?它们没有任何功能,但应删除它们.
我已经看到,因为LollipopAndroid已经Emoji为不同的国家建立了标志.是否可以使用设备区域设置来检索该Emoji国家/地区的标志?
我想将Emoji标志插入TextView包含用户位置的标志.
这已经困扰了我一段时间了.我有一个UISplitViewController内部UITabBarController.主视图是TableView.当我点击一个单元格时,我会调出一个非常基本的视图控制器,只有一个UIButton居中.以下是视图控制器的代码:
class TestViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var button: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func buttonPressed(sender: AnyObject) {
let pickerC = UIImagePickerController()
pickerC.delegate = self
pickerC.modalPresentationStyle = .Popover
pickerC.popoverPresentationController?.sourceView = button as UIView
pickerC.popoverPresentationController?.sourceRect = (button as UIView).bounds
pickerC.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Any
self.presentViewController(pickerC, animated: true, completion: nil)//4
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: …Run Code Online (Sandbox Code Playgroud) 今天Xcode在尝试将构建上传到iTunes连接时给了我一些问题.它给了我以下错误:
我的申请CFBundleVersionShortVersionString是多么奇怪2.0.0.我昨天上传了一个版本到TestFlight,它运行得很好.于是我做了一个搜索CFBundleVersionShortVersionString,我发现一个1.0.0和0.5.1,但他们在info.plist在豆荚.为什么这个错误突然出现?我知道我不应该改变Pod中的任何东西.有没有人遇到过这个问题,如果有的话你怎么解决这个问题?
我正在为大型视频文件创建MD5校验和.我目前正在使用代码:
extension NSData {
func MD5() -> NSString {
let digestLength = Int(CC_MD5_DIGEST_LENGTH)
let md5Buffer = UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: digestLength)
CC_MD5(bytes, CC_LONG(length), md5Buffer)
let output = NSMutableString(capacity: Int(CC_MD5_DIGEST_LENGTH * 2))
for i in 0..<digestLength {
output.appendFormat("%02x", md5Buffer[i])
}
return NSString(format: output)
}
}
Run Code Online (Sandbox Code Playgroud)
但这会产生一个内存缓冲区,对于大型视频文件来说并不理想.在Swift中有没有办法计算读取文件流的MD5校验和,因此内存占用量最小?
似乎任何使用Marshmallow(Android 6.0)的人都无法DatePicketDialog在我的应用程序中使用.似乎遇到了某种我遇到的主题问题.我用一个DialogFragment包含一个DatePicketDialog供用户选择生日.以下是Android 5.x和6.x的DialogFragment镜头.
我试图在DatePickerDialog构造函数中添加一个主题,但这使得DialogFragment全屏,我不希望这样.有谁知道我怎么能看到DatePickerDialog它像棉花糖之前?
更新1
这是我创建的代码DialogFragment:
DialogFragment ageFragment = new DatePickerDialogFragment();
ageFragment.show(getFragmentManager(), "datePicker");
Run Code Online (Sandbox Code Playgroud)
这是onCreateDialog里面的DatePickerDialogFragment:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker if no filters are set
Calendar cal = Calendar.getInstance();
// Set the date 18 years previous, since only 18 and older are allowed on the app
cal.add(Calendar.YEAR, -18);
int year, …Run Code Online (Sandbox Code Playgroud) 我有一个 UISplitViewController,我想在其中始终显示 iPad 的主视图控制器和详细视图控制器。这条线为我解决了这个问题:
// Always display master and detail in large screens
self.preferredDisplayMode = UISplitViewControllerDisplayMode.AllVisible
Run Code Online (Sandbox Code Playgroud)
在prepareForSegue中,当打开详细视图控制器时,我有以下后退按钮代码行
controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
controller.navigationItem.leftItemsSupplementBackButton = true
Run Code Online (Sandbox Code Playgroud)
现在,当用户按下后退按钮时,我想在隐藏主视图控制器后执行一个操作。我没有运气找到如何做到这一点。在 SplitViewControllerDelegate 中我尝试使用:
func splitViewController(svc: UISplitViewController, willChangeToDisplayMode displayMode: UISplitViewControllerDisplayMode)
Run Code Online (Sandbox Code Playgroud)
但该函数是在详细视图控制器变为全屏之前调用的。当 UISplitViewController 完成隐藏主视图时,是否有功能或其他功能可以帮助通知我?