Error initialize AZSCloudStorageAccount Swift 3 - ios

I tried link to my account with this code
let storageAccount : AZSCloudStorageAccount;
try! storageAccount = AZSCloudStorageAccount(fromConnectionString: config.getAzureConnection())
let blobClient = storageAccount.getBlobClient()
var container : AZSCloudBlobContainer = (blobClient?.containerReference(fromName: config.getContainer()))!
the "config.getAzureConnection()" contains the right path because i used the same for android app.
In this line try! storageAccount = AZSCloudStorageAccount(fromConnectionString: config.getAzureConnection()) the app crash without error, only (lldb) .
Can someone help me.

Does your error look like this?
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=com.Microsoft.AzureStorage.ErrorDomain Code=1 "(null)": file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-802.0.53/src/swift/stdlib/public/core/ErrorType.swift, line 182
(lldb)
Code=1 is AZSEInvalidArgument, which means that your connection string is invalid. I am a bit confused why you said "the right path", since fromConnectionString takes the string directly, not the path to a file. To see an example of what a correct connection string looks like, please refer to the Getting Started Guide. Basically it looks like this:
"DefaultEndpointsProtocol=https;AccountName=your_account_name_here;AccountKey=your_account_key_here"
We will document the error codes properly very soon. Sorry for the confusion!

the app crash without error, only (lldb) .
I am sorry for that SWIFT blob client haven't provide error-handling code whatsoever currently. I will provide some clues to track your issue based on your code.
Before building the storage code, make one change in the project. Go to 'Azure Storage Client Library' -> Build Settings, search for the "Defines Module" setting, and change it to 'YES'.
Please check whether the issue is caused by bad network connection.
You could get error code of this issue by putting your code in a do-catch code block.
do {
//put your code here
} catch let error as NSError {
print("Error code = %ld, error domain = %#, error userinfo = %#", error.code, error.domain, error.userInfo);
}
The SWIFT blob sample has been tested and work well targeting iOS 9.0 and using XCode 7. If you have a different setup, the sample may not run properly. I suggest you use Blob Storage REST API as a workaround.

Related

Logging Additional Information for Error Reporting

In our error logging, we are using Crashlytics.
Now there are 2 ways that we log errors:
The automatic logging (when the app has crashed) done when the app starts up again.
Immediate logging using the Swift SDK
In case 1. it seems that there is no way of logging additional information.
However, in case 2. we use the following call :
Crashlytics.sharedInstance().recordError(error, withAdditionalUserInfo:additionalInfo)
With additionalInfo being a simple set of KVP's ["ListingNumber": "abcAsEasyAs123"]
However, this does not show up on the portal as well as in the .txt download that they offer.
We then amended our logging method to try and attach the additional info to the error itself.
if let error = error {
let newError = NSError(domain: (error as NSError).domain, code: (error as NSError).code, userInfo: ["ListingNumber": "abcAsEasyAs123"])
Crashlytics.sharedInstance().recordError(newError)
}
However, even in this case, the additional info is nowhere to be found.
According to the documentation, this should be possible, but nothing I am doing is showing.
EDIT: This is not a duplicate of that question as I have read it and referenced the same material that the accepted answer used.

Can't read or create UIManagedDocuments anymore

I have a big issue in my app, which prevents creating new documents and reading them, whereas it worked well until now.
I didn't change anything, and it started bugging from a build to another.
This is the code I'm using:
CLProject *project = [[CLProject alloc] initWithFileURL:projectURL];
NSLog (#"Will save project at URL: %#", projectURL);
[project saveToURL:projectURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
NSLog (#"Project saved: %d", success);
[...]
}];
CLProject is a subclass of UIManagedDocument.
The first NSLog is called, but not the second one. Instead I get an error :
2018-02-14 19:21:03.597495+0100 CamList[2247:750786] Will save project
at URL:
file:///var/mobile/Containers/Data/Application/151E38F5-2214-4876-A188-2AB8B5E8CF6A/Documents/Projects/715A0087-F2EF-439B-A2DD-8E878EF8A973.camlist
2018-02-14 19:21:03.783397+0100 CamList[2247:750886] [default] [ERROR]
Could not get attribute values for item
/var/mobile/Containers/Data/Application/151E38F5-2214-4876-A188-2AB8B5E8CF6A/Documents/Projects/715A0087-F2EF-439B-A2DD-8E878EF8A973.camlist
(n). Error: Error Domain=NSFileProviderInternalErrorDomain Code=1 "The
reader is not permitted to access the URL."
UserInfo={NSLocalizedDescription=The reader is not permitted to access
the URL.}
But it doesn't crash, the app keeps running (but nothing happens because the completion block never gets called).
What I don't understand is that everything was working fine and I haven't changed anything...
Can you help me??
Thanks
Well, it seems to work fine again this morning... Nothing to understand. My iPhone had to be tired...

Realm exception Error Domain=io.realm Code=2 "Operation not permitted"

I am struggeling with using a new defaultConfiguration for Realm (I think so...)
So what do I try to achieve. I'd like to change the default Realm URL to an Apple App group based ID because I want to use the same Realm from both the Today Extension of my App as well as my App itself.
I found a (slightly outdated Realm tutorial for WatchKit Extension ) where thy put the following to the AppDelegate:
realmUrl: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.net.exchange.On")!
realmUrl.URLByAppendingPathComponent("db.realm")
var config = Realm.Configuration.defaultConfiguration
config.fileURL = realmUrl
Realm.Configuration.defaultConfiguration = config
This works. But my coding to read from Realm, which was working before that, now crashes with the exeption:
This was working up to that change: `let realm = try! Realm()``
But now it creates this beautiful error ;-)
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=io.realm
Code=2 "Operation not permitted" UserInfo={Error Code=2,
NSFilePath=/private/var/mobile/Containers/Shared/AppGroup/4E8402AD-89E4-4138-8B83-CA6B409BB238,
Underlying=n/a, NSLocalizedDescription=Operation not permitted}:
file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-703.0.18.8/src/swift/stdlib/public/core/ErrorType.swift, line 54
I am a bit lost. Hopefully anybody can help me out. TIA John
The problem is that the path fileURL you're setting on Realm's configuration is the path to your app group container, not the path to a file within it. This is due to the following piece of the code:
let realmUrl: NSURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.net.exchange.On")!
realmUrl.URLByAppendingPathComponent("db.realm")
NSURL.URLByAppendingPathComponent(_:) returns a new URL rather than mutating the existing one. Changing the code to something like the following should result in the correct URL being set on the Realm's configuration:
let groupContainerUrl = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("group.net.exchange.On")!
let realmUrl = groupContainerUrl.URLByAppendingPathComponent("db.realm")

Error in iOS: "you don't have permission"

I'm working on an iOS project in Swift which uses the Dropbox API to upload text files to Dropbox as well as load and read them from Dropbox. However, when I try to load a file using my DBRestClient using the following line:
restClient.loadFile("/data/" + yearStr + "/" + yearMonthStr + "/" + fullStr + ".txt", atRev: nil, intoPath: "temp2.txt")
I see the following error message in the console:
DropboxSDK: error making request to /1/files/sandbox/data/15/15_12/15_12_10.txt - (404) Path is a directory`
I'm not really sure what this means, since neither path involved in the call looks like a directory to me. I've searched for this error message but I can't seem to find it anywhere online, and I'm not sure what else might have caused it since commenting out this line prevents the error fro showing up and the same filepath works fine in other calls that don't involve loading files. Am I missing something about how loadFile() works?
UPDATE: I fixed the previous error by deleting a directory with the that filepath, making it choose the correct file. However, I am now getting the following error instead:
DropboxSDK: error making request to /1/files/sandbox/data/15/15_12/15_12_10.txt - (513) Error Domain=NSCocoaErrorDomain Code=513 "The file couldn’t be saved because you don’t have permission." UserInfo={path=/data/15/15_12/15_12_10.txt, destinationPath=temp2.txt}
I'm not sure what it means-- do I not have permission for the destination on my phone, or for the file on dropbox? I'm looking up this error message but I'm not finding anything yet, so help would be much appreciated.
According to the documentation, code 513 corresponds to:
NSFileWriteNoPermissionError = 513,
That seems to match the error message you get, and should be referring to the local destination path, which in your case is:
temp2.txt
You should check that you have access to write to that local path, and that it's a valid path, e.g., should it start with a '/'?. (Or moreover, perhaps you should be writing to NSTemporaryDirectory or something like that.)

ContentExtensionsDomain error 1

I am trying to use "reloadContentBlockerWithIdentifier" function of SFContentBlockerManager as follows:
[SFContentBlockerManager reloadContentBlockerWithIdentifier:#"appid.extensionid"
completionHandler: ^ (NSError *error) {
NSLog("%#", error.localizedDescription)
}
However, it only returns error message that said as follows:
The operation couldn’t be completed. (ContentExtensionsDomain error 1.)
I set both APP IDs (appid and appid.appextensionid) in "Certificates, Identifiers & Profiles" in developer.apple.com. Also, I made two "target"s for each -- ios app and ios app extension. I also checked open source implementations in Github which are roughly the same as mine, and App Extension manual several times, but it seems hard to find the relevant page for this problem. The most critical problem is: I couldn't find any offcial documents describing this message.
I'd appreciate if you let me know what is the problem.
Looking at the safari services generated swift interface, I could find the following enum for error codes:
public enum SFContentBlockerErrorCode : Int {
case NoExtensionFound
case NoAttachmentFound
case LoadingInterrupted
}
So in your case it's probably the NoAttachmentFound error. Which can be caused by failure to initialise an item provider with given data from a json file.

Resources