在我的应用程序中,我需要使用.gif
,我搜索了它.每个人都要求使用UIImage.gifImageWithName("funny")
或UIImage.gifWithName("jeremy")
添加.gif
文件.但我得到的错误Type 'UIImage' has no member 'gifWithName'
.如何解决这些问题以及如何.gif
在我的应用程序中使用.
在我的应用程序中,我有一个功能,可以拍摄照片camera
并将其上传到服务器.我的问题是,当我从服务器得到响应时,图像旋转到90度左侧.这是我尝试过的代码:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
{
self.PickerFrom = self.PickerFrom2
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage
{
self.AttachmentImageView.image = pickedImage
}
dismiss(animated: true, completion: nil)
uploadGalleryImage(image: self.AttachmentImageView.image!)
}
func uploadGalleryImage( image:UIImage)
{
let imageData: NSData = UIImagePNGRepresentation(image)! as NSData
let base64String = imageData.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0))
self.AttachedDocumentURL = "data:image/png;base64,\(base64String)"
}
Run Code Online (Sandbox Code Playgroud)
AttachedDocumentURL
包含捕获图像的base64sting.
我在我的应用中使用Firebase通知.当我第一次安装我的应用程序时FIRInstanceID.instanceID().token()
返回nil,但下次不会返回nil.除此之外,一切都做得很完美.
这是代码:
import UIKit
import Firebase
import FirebaseMessaging
import FirebaseInstanceID
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, FIRMessagingDelegate
{
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
//Configuring Firebase
FIRApp.configure()
if #available(iOS 10.0, *)
{
print("Test")
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.badge, .sound, .alert]) { (granted, error) in
if granted
{
//self.registerCategory()
}
}
// For iOS 10 data message (sent via FCM)
FIRMessaging.messaging().remoteMessageDelegate = self
}
else
{ …
Run Code Online (Sandbox Code Playgroud) 在我的应用中,我正在打开文件下载。一切都做得很完美,但是问题是zip,rar,tar文件等文件正在下载,但下载完成后这些文件将不会显示。这是我尝试的代码:
func DownloadDocumnt()
{
let sucessAlert = UIAlertController(title: "Download Files", message: "Download the file \(self.TopLbl.text!) to your mobile for offline access.", preferredStyle: UIAlertControllerStyle.alert)
sucessAlert.addAction(UIAlertAction(title: "Start Download", style: UIAlertActionStyle.default, handler: { action in
self.view.makeToastActivity(message: "Downloading...")
let fileURL = URL(string: "\(self.DocumentURL)")!
let documentsUrl:URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first as URL!
let destinationFileUrl = documentsUrl.appendingPathComponent("\(self.TopLbl.text!)")
let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig)
let request = URLRequest(url:fileURL)
let task = session.downloadTask(with: request) { (tempLocalUrl, response, error) in
if let tempLocalUrl = tempLocalUrl, …
Run Code Online (Sandbox Code Playgroud) 这是我在前台app时用来接收推送通知的代码
@available(iOS 10.0, *)
func userNotificationCenter(center: UNUserNotificationCenter, willPresentNotification notification: UNNotification, withCompletionHandler completionHandler: (UNNotificationPresentationOptions) -> Void)
{
completionHandler([UNNotificationPresentationOptions.Alert,UNNotificationPresentationOptions.Sound,UNNotificationPresentationOptions.Badge])
}
Run Code Online (Sandbox Code Playgroud)
但我的问题是我的通知包含[NSObject:AnyObject]值.如何接收类似的背景通知
我正在使用 iOS 10 和 swift 2.3,当收到来自 firebase 的新通知时,我需要增加徽章计数。我有增加徽章数量的代码
let badgeCount: Int = BadgeCount + 1
UIApplication.sharedApplication().applicationIconBadgeNumber = badgeCount
Run Code Online (Sandbox Code Playgroud)
但我不知道在哪里使用它才能使其正常工作。
是否可以从App Store获取我的应用程序的最新版本.我只需要将我的应用程序版本与App Store最新版本进行比较,并让用户强制更新.
在我的应用程序中,我们使用Realm Storage在本地存储值。我可以将数组值存储为字符串。但不能将值存储和检索为数组。是否可以将NSArray值存储到Realm对象并将其检索为NSArray。这是我用来存储字符串值的代码:
class PracticeView: Object
{
dynamic var PracticeArray = ""
}
Run Code Online (Sandbox Code Playgroud)
和用法:
let realm:Realm = try! Realm()
let PracticeDetails = PracticeView()
PracticeDetails.PracticeArray = "Test String Values"
try! realm.write
{
realm.add(PracticeDetails)
}
print("Values In Realm Object: \(PracticeDetails.PracticeArray)")
//Result Will Be
Values In Realm Object: Test String Values
Run Code Online (Sandbox Code Playgroud) 我在scrollview中有两个子视图.我需要以编程方式定位两个子视图.我通过在里面编写代码来正确地做到了DispatchQueue.main.async
.这是代码:
DispatchQueue.main.async
{
self.SelectClientDetailView.frame = CGRect(x: 0, y: 637, width: self.SelectClientDetailView.frame.size.width, height: self.SelectClientDetailView.frame.size.height)
self.SelectClientDetailView2.frame = CGRect(x: 0, y: 837, width: self.SelectClientDetailView2.frame.size.width, height: self.SelectClientDetailView2.frame.size.height)
}
Run Code Online (Sandbox Code Playgroud)
它工作得很好但是当我滚动我的滚动视图时,这两个视图都回到了原来的位置.如何解决它.其默认y
位置为SelectClientDetailView
:400和SelectClientDetailView2
:600
我有文件下载选项。当用户从我的应用程序下载文档时,我需要将其存储到已经安装在用户移动设备中的用户iCloud Drive中。我已经在Web和Xcode中都配置了iCloud,但是问题是我无法正确将文件复制到iCloud Drive。文件已成功下载,并且也已移至iCloud,但文件不会出现在iCloud Drive App中。这是我尝试的代码:
<key>NSUbiquitousContainers</key>
<dict>
<key>iCloud.MyAppBundleIdentifier</key>
<dict>
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
<true/>
<key>NSUbiquitousContainerName</key>
<string>iCloudDriveDemo</string>
<key>NSUbiquitousContainerSupportedFolderLevels</key>
<string>Any</string>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)
这是我的iCloud存储代码:
func DownloadDocumnt()
{
print("Selected URL: \(self.SelectedDownloadURL)")
let fileURL = URL(string: "\(self.SelectedDownloadURL)")!
let documentsUrl:URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first as URL!
let destinationFileUrl = documentsUrl.appendingPathComponent("Libra-\(self.SelectedDownloadFileName)")
let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig)
let request = URLRequest(url:fileURL)
let task = session.downloadTask(with: request) { (tempLocalUrl, response, error) in
if let tempLocalUrl = tempLocalUrl, error == nil
{
if let statusCode = (response as? …
Run Code Online (Sandbox Code Playgroud) 将我的代码升级到 Swift 5 后,Firestore 返回NSDate
为FIRTimestamp
. 当我尝试接收它时,Date
它抛出错误:
无法将类型“FIRTimestamp”(0x107aab8c0)的值转换为“NSNumber”(0x10b8fbe00)。
如何解决这个问题?
在 firestore 中,我们添加了多个字段,但没有指定 documentID(自动 ID)。我需要更新特定的字段值,例如:
这是我尝试过的代码
self.DBRef.collection("users").whereField("name", isEqualTo: "kavin")
如何更新此字段值