stringWithContentsOfURL gives null value - objective-c

Hi I'm trying to get a number from a text file in my server but i'm getting a null value this is the code... I have reed many similar posts trying to solve the problem but non of them has been useful
NSURL *url = [NSURL URLWithString:#"http://www.trailrunningcamp.cl/version.txt"];
NSError* error = nil;
NSString *content = [NSString stringWithContentsOfURL:url encoding:NSASCIIStringEncoding error:&error];
NSLog(#"Content = %#", content );
I have added this code to my plist but still got the same result
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>trailrunningcamp.cl</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
I'm using Xcode 7.2.1 and OS X El Capitan 10.11.3.... before that code worked fine (a year ago) but with the new Xcode does not work... Is it a missconfiguration or a code error?

Related

Unable to select file when using UIDocumentPickerViewController initForOpeningContentTypes

I'm trying to use the iOS 14 initForOpeningContentTypes: rather than the deprecated initWithDocumentTypes:inMode: and I'm unable to get access to files with the extension p8 (they are greyed out).
I'm trying the following code:
NSArray<UTType*> * contentTypes = #[[UTType typeWithFilenameExtension: #"p8"
conformingToType: UTTypeData]];
UIDocumentPickerViewController *documentPicker = nil;
documentPicker = [[UIDocumentPickerViewController alloc] initForOpeningContentTypes: contentTypes];
The picker launches, but the file "myfile.p8" is greyed out and unselectable. What am I doing wrong here?
Once I added the following to my application’s Info.plist I was able to select the file:
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeIdentifier</key>
<string>com.my-company.my-identifier</string>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>My Description</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>p8</string>
</array>
</dict>
</dict>
</array>
Apparently it tells the system about the type. See this answer for info about UTExportedTypeDeclarations.

Cannot Fetch more than one key arrays from my Info.plist file

i am trying to fetch two arrays against two keys in my Info.plist but instead not getting any data in my output. here is my code.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0),^{
NSString *post = [NSString stringWithFormat:#"URL"];
NSDictionary *dTmp = [[NSDictionary alloc] initWithContentsOfURL:[NSURL URLWithString:post]];
NSMutableArray *OriginalDetailsArray=[dTmp valueForKey:#"Objects"];
NSMutableArray *OriginalGalleryArray=[dTmp valueForKey:#"gallery"];
detailsArray=[[NSMutableArray alloc] init];
[detailsArray addObjectsFromArray:OriginalDetailsArray];
galleryArray=[[NSMutableArray alloc] init];
[galleryArray addObjectsFromArray:OriginalGalleryArray];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"%#, %#",detailsArray, galleryArray);
});
});
Out Put is: You can see there is nothing in the output just empty brackets.
(
), (
)
here is my Info.plist file. if i remove second array "Gallery" and i only let "Objects" data fetches perfectly. But after adding Second Array it gives empty output.
<plist version="1.0">
<dict>
<key>Objects</key>
<array>
<dict>
<key>propid</key>
<integer>233</integer>
<key>title</key>
<string>101 Perthshire Private</string>
<key>type</key>
<string>For Sale</string>
<key>price</key>
<string>$899,900</string>
<key>bed</key>
<string>2</string>
<key>bath</key>
<string>3</string>
</dict>
</array>
</dict>
<dict>
<key>gallery</key>
<array>
<dict>
<key>imageurl</key>
<string>
/images/23330.jpg
</string>
</dict>
<dict>
<key>imageurl</key>
<string>
/images/23333.jpg
</string>
</dict>
<dict>
<key>imageurl</key>
<string>
/images/23339.jpg
</string>
</dict>
</array>
</dict>
</plist>
Your plist data formot are wrong. Please put below code on your php file and check it.
<plist version="1.0">
<dict>
<key>Objects</key>
<array>
<dict>
<key>propid</key>
<integer>233</integer>
<key>title</key>
<string>101 Perthshire Private</string>
<key>type</key>
<string>For Sale</string>
<key>price</key>
<string>$899,900</string>
<key>bed</key>
<string>2</string>
<key>bath</key>
<string>3</string>
</dict>
</array>
<key>gallery</key>
<array>
<dict>
<key>imageurl</key>
<string>/images/23330.jpg</string>
</dict>
<dict>
<key>imageurl</key>
<string>/images/23333.jpg</string>
</dict>
<dict>
<key>imageurl</key>
<string>/images/23339.jpg
</string>
</dict>
</array>
</dict>
</plist>
Please Try Below Code, I got Result.
NSArray *arrayObjects = [NSArray arrayWithArray:[dictRoot objectForKey:#"Objects"]];
NSArray *arrayGallery = [NSArray arrayWithArray:[dictRoot objectForKey:#"gallery"]];
NSLog(#"%#",arrayObjects);
NSLog(#"%#",arrayGallery);

AWSS3TransferManager - Terminating app due to uncaught exception

I am creating a cordova plugin to upload images to s3.
When I build the project I get the following error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'The service configuration is `nil`. You need to configure `Info.plist` or set `defaultServiceConfiguration` before using this method.'
I have followed other answers on here and added the extra keys to the info.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIcons~ipad</key>
<dict>
<key>CFBundlePrimaryIcon</key>
<dict>
<key>CFBundleIconFiles</key>
<array>
<string>icon-small</string>
<string>icon-40</string>
<string>icon-50</string>
<string>icon-76</string>
<string>icon-72</string>
<string>icon</string>
</array>
</dict>
</dict>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>4.28.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>0.0.1</string>
<key>Fabric</key>
<dict>
<key>APIKey</key>
<string></string>
<key>Kits</key>
<array>
<dict>
<key>KitInfo</key>
<dict/>
<key>KitName</key>
<string>Crashlytics</string>
</dict>
</array>
</dict>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>DynamoDBObjectMapper</key>
<dict>
<key>Default</key>
<dict>
<key>Region</key>
<string>eu-west-1</string>
</dict>
</dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>amazonaws.com</key>
<dict>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>amazonaws.com.cn</key>
<dict>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>localhost</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSLocationUsageDescription</key>
<string>Geolocation information is used to tag assessments and assessment contents with the users location. This is only used when conducting an assessment.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Geolocation information is used to tag assessments and assessment contents with the users location. This is only used when conducting an assessment.</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UIRequiresFullScreen</key>
<true/>
<key>UIStatusBarHidden~ipad</key>
<true/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>AWS</key>
<dict>
<key>S3TransferManager</key>
<dict>
<key>Default</key>
<dict>
<key>Region</key>
<string>eu-west-1</string>
</dict>
</dict>
</dict>
</dict>
</plist>
This is the function in the plugin.
- (void)uploadImage:(CDVInvokedUrlCommand*)command
{
AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
NSString* filePath = [command argumentAtIndex:0 withDefault:nil];
NSURL *uploadingFileURL = [NSURL fileURLWithPath: filePath];
AWSS3TransferManagerUploadRequest *uploadRequest = [AWSS3TransferManagerUploadRequest new];
uploadRequest.bucket = #"my-test-bucket";
uploadRequest.key = #"mykey";
uploadRequest.body = uploadingFileURL;
[[transferManager upload:uploadRequest] continueWithExecutor:[AWSExecutor mainThreadExecutor]
withBlock:^id(AWSTask *task) {
if (task.error) {
if ([task.error.domain isEqualToString:AWSS3TransferManagerErrorDomain]) {
switch (task.error.code) {
case AWSS3TransferManagerErrorCancelled:
case AWSS3TransferManagerErrorPaused:
break;
default:
NSLog(#"Error: %#", task.error);
break;
}
} else {
// Unknown error.
NSLog(#"Error: %#", task.error);
}
}
if (task.result) {
AWSS3TransferManagerUploadOutput *uploadOutput = task.result;
// The file uploaded successfully.
}
return nil;
}];
}
The exception is thrown at line:
AWSS3TransferManager *transferManager = [AWSS3TransferManager defaultS3TransferManager];
I found a solution using the answer provided in https://stackoverflow.com/a/39957439/3191747
Adding the following to didFinishLaunchingWithOptions in the AppDelegate solved the problem:
AWSStaticCredentialsProvider *credentialsProvider = [[AWSStaticCredentialsProvider alloc] initWithAccessKey:AWS_ACCESS_KEY secretKey:AWS_SECRET_KEY];
AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionAPSoutheast1
credentialsProvider:credentialsProvider];
AWSServiceManager.defaultServiceManager.defaultServiceConfiguration = configuration;

iOS - (kCFStreamErrorDomainSSL, -9813)

I'm getting (kCFStreamErrorDomainSSL, -9813) when connecting to a client's server.
The client's server has a self signed certificate that I can not change. The app is using AFNetworking 3.x. I've tried the following but nothing seems to work.
If someone could help me, it will be much appreciated.
Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key> *** CLIENT HOSTNAME *** </key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSTemporaryExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
AFNetworking connection manager:
AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc]initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
#ifdef USE_SELF_SIGNED_CERT_RULES
manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
manager.securityPolicy.allowInvalidCertificates = YES;
manager.securityPolicy.validatesDomainName = YES;
#endif
I had the same problem. I tried your solution but it did not work. Settings allowInvalidCertificates , validatesDomainName and AFSSLPinningModeCertificate did not solved my problem. After going through lots of googling I saw the structure of AFSecurityPolicy this class.
There is a function in this class
- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust
forDomain:(nullable NSString *)domain;
You have to subclass the AFSecurityPolicy and return YES in its implementation. Then you will be able to connect to your server.
My client server was also self-signed.
Settings properties on AFSecurityPolicy does not solve the problem, I wonder why.

Assigning UTI to file type

I'm trying to add UTI for a pair of file types, matching by extension. I think I've got it setup properly - at the very least, the file extension -> UTI mapping is recognized (I declared it as an imported type in info.plist). However, when I try to get the UTI off of my test file, I get back a dynamic UTI. Here's the sample code I'm using to test these two cases:
NSString *previewTypeUTI = nil;
NSURL *previewFileURL = [NSURL fileURLWithPath:#"/Users/eblair/Desktop/EWF/thetestfile.myext1"];
[previewFileURL getResourceValue:&previewTypeUTI forKey:NSURLTypeIdentifierKey error:nil];
NSLog(#"%#", previewTypeUTI); // #1
NSString *testUTI = (NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (CFStringRef)[previewFileURL pathExtension], NULL);
NSLog(#"%#", testUTI); // #2
[testUTI release];
NSLog #1 prints out "dyn.########" and NSLog #2 prints out "com.mycompany.filetype1". I would've expected them to print the same thing. Is there some extra step to get the file->UTI mapping working or is it a case of Launch Services needing to catch up?
Just using the extension->UTI mapping isn't an option because I want to use some APIs that take advantage of UTIs and those APIs seem to be using the file->UTI mapping.
For the sake of completeness, here's the plist entry for the imported types:
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.disk-image</string>
</array>
<key>UTTypeDescription</key>
<string>File Type 1</string>
<key>UTTypeIdentifier</key>
<string>com.mycompany.filetype1</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>myext1</string>
</array>
</dict>
</dict>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.disk-image</string>
</array>
<key>UTTypeDescription</key>
<string>File Type 2</string>
<key>UTTypeIdentifier</key>
<string>com.mycompany.filetype2</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>myext2</string>
</array>
</dict>
</dict>
</array>
Well, it's been close to a year, but I had to re-address this today and I think I stumbled across what I did wrong. It looks like you need to include public.data as a type you conform to, even though public.disk-image already conforms to public.data. So, the UTTypeConformsTo array should look like this:
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
<string>public.disk-image</string>
</array>
After making this change, my above comparison of the file->UTI and extension->UTI now yield the same result.