Unable to read Images from xcode project in iPad IOS 10.2.1 64bit when download app from app store (testflight) - ios

Unable to read Images from xcode project for example.
drag and drop one image to xcode project, then read using following code.
__weak NSString *strTemp = [NSString stringWithFormat:#"%#/s_%#",[[NSBundle mainBundle] resourcePath],[[self.arr_gallery objectAtIndex:i]valueForKey:#"filename_larger"]];
strTemp = [strTemp substringToIndex:[strTemp length]-3];
strTemp = [NSString stringWithFormat:#"%#png",strTemp];
// NSString *strTemp = [[NSString alloc] initWithFormat:#"%#/s_BGP001#2x.png",[[NSBundle mainBundle] resourcePath]];
UIImage *image;
image = [[UIImage alloc] initWithContentsOfFile:strTemp];
img.image = image;
strTemp = nil;

Write following code.
NSString *newStrTemp = [strTemp stringByReplacingOccurrencesOfString:#"jpg" withString:#"png"];
Instead of this one.
strTemp = [strTemp substringToIndex:[strTemp length]-3];
strTemp = [NSString stringWithFormat:#"%#png",strTemp];

Related

Can't find the new image in the blue reference folder

Now my app has a blue reference folder, and the app can load images.\
The code is below:
NSString *bundelPath = [[NSBundle mainBundle] pathForResource:#"YSPSdk" ofType:#"bundle"];
NSBundle *sdkBundle = [NSBundle bundleWithPath:bundelPath];
for (int i = 1; i <= 72; i++)
{
NSString *imageName = [NSString stringWithFormat:#"adapte_animation_%03d#3x",i];
NSString *imagePath = [sdkBundle pathForResource:imageName ofType:#"png" inDirectory:#"Loading"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
[_imageArray addObject:image];
}
The app builds and runs well.
Then I add some new images into this folder, and change the code as below:
for (int i = 1; i <= 12; i++)
{
NSString *imageName = [NSString stringWithFormat:#"animation_%03d",i];
NSString *imagePath = [sdkBundle pathForResource:imageName ofType:#"png" inDirectory:#"Loading"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
[_imageArray addObject:image];
}
The app will crash.
Then I debugged this app and set a breakpoint in the code.
I see the image not be created.
Why?
I must replace the old image with the new image.
What is a remedy in this case?
==============
I rename some old Images and edit the code to load this new name old images.
I run the app, the app shows me the same error:
It can't find the imagePath!
In my main project. TARGETS -> Build Phases -> Copy Bundle Resources.
I delete the YSPSdk.bundle and add it again. I solve the problem.

iOS Objective-C Display PNG Image In Custom Framework

I'm creating a custom framework. Previously in the framework we would download an image and use that to display in a button:
NSString *path = [NSString stringWithFormat: #"https://s3.amazonaws.com/assets/home.png"];
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *homeButton = [[UIImage alloc] initWithData:data];
self.rewardsCenterButton = [[UIBarButtonItem alloc] initWithImage:[homeButton imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
style:UIBarButtonItemStylePlain
target:self
action: #selector(backToRewardsCenter:)];
However, in reviewing this we determined that this isn't good to have as a synchronous call so I'd like to add this PNG to the framework itself.
I've been able to do this by adding the image and ensuring it's included in the copy bundle resources Build Phase. With this set the image gets added in the universal framework output:
However, when I attempt to add this in code, it doesn't seem to show up. Also, when I add the framework in a project, I don't see the image being included, just the headers:
Here's what I've tried so far:
NSString* path = [NSString stringWithFormat:#"%#/TheoremReachSDK.framework/home.png", [[NSBundle mainBundle] bundlePath]];
UIImage *homeButton = [[UIImage alloc] initWithContentsOfFile:path];
And:
NSBundle *bundle = [NSBundle bundleForClass:[TheoremReach class]];
NSString *path = [bundle pathForResource:#"home" ofType:#"png"];
UIImage *homeButton = [[UIImage alloc] initWithContentsOfFile:path];
And:
UIImage *homeButton = [UIImage imageNamed:#"home.png"];
But none of those display anything. Any idea what I need to do to get the image to display?
I'm guessing NSBundle isn't finding the framework via the call to:
[NSBundle bundleForClass:[TheoremReach class]]
Try giving your framework an explicit bundle ID, e.g.: com.theoremreach.sdk, clean your projects and then rebuild.
You can then use code like this to fetch and display your image:
NSString *bundleIdentifier = #"com.theoremreach.sdk";
NSBundle *bundle = [NSBundle bundleWithIdentifier:bundleIdentifier];
if(bundle != nil) {
NSString *path = [bundle pathForResource:#"home" ofType:#"png"];
UIImage *homeButtonImage = [[UIImage alloc] initWithContentsOfFile:path];
if(homeButtonImage != nil) {
self.rewardsCenterButton = [[UIBarButtonItem alloc] initWithImage:[homeButtonImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
style:UIBarButtonItemStylePlain
target:self
action: #selector(backToRewardsCenter:)];
} else {
NSLog(#"couldn't find home button image in bundle");
}
} else {
NSLog(#"could not find bundle with identifier %#", bundleIdentifier);
}

How to set image into uiwebview?

I have created a html code like see above and the code uploaded to http://www.ged.Ic.com site.
Added an image name “1.jpg” into Xcode project.
When open iPad app loading http://www.ged.Ic.com/page/ from webview.
How to get to set image from into Xcode project to img src="image path from xcode"
NSString *imageFileName = #"image";
NSString *imageFileExtension = #"png";
NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageFileName ofType:imageFileExtension];
NSString *imgHTMLTag = [NSString stringWithFormat:#"<img src=\"file://%#\" />", imagePath];
NSString *imageUrlString = #"http://www.gstatic.com/translate/intl/ru/logo.png";
NSString *yourText = #"Some text here";
NSString *htmlString = [NSString stringWithFormat:#"<img src='%#'/><br><b>%#</b>", imageUrlString, yourText];
[myWebView loadHTMLString:htmlString baseURL:nil];

Post image from local bundle to PinInterest iphone.

I have implemented the PinInterest through web view using this code:
NSString *description = #"Post your description here";
NSURL* sUrl = [NSString stringWithFormat:#"http://4.bp.blogspot.com/-w4oTZjlpgwo/T5_pi-KJPuI/AAAAAAAAAoM/rKm3E0XCbgY/s1600/red_rose_flower3.jpg"];// pass your link here with your image name
// NSLog(#"URL:%#", sUrl);
NSString *protectedUrl = ( NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,( CFStringRef)sUrl, NULL, (CFStringRef)#"!*'\"();:#&=+$,/?%#[]% ",CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)));
NSLog(#"Protected URL:%#", protectedUrl);
NSString *imageUrl = [NSString stringWithFormat:#"\"%#\"", sUrl];
imageUrl=[[NSBundle mainBundle]pathForResource:mAppDelegate.imagename ofType:nil];
NSString *buttonUrl = [NSString stringWithFormat:#"\"http://pinterest.com/pin/create/button/?url=www.flor.com&media=%#&description=%#\"", protectedUrl, description];
NSMutableString *htmlString = [[NSMutableString alloc] initWithCapacity:1000];
[htmlString appendFormat:#"<html> <body>"];
[htmlString appendFormat:#"<p align=\"center\"><img border=\"0\" src=\"http://assets.pinterest.com/images/PinExt.png\" title=\"Pin It\" /></p>", buttonUrl];
[htmlString appendFormat:#"<p align=\"center\"><img width=\"300px\" height = \"400px\" src=%#></img></p>", imageUrl];
[htmlString appendFormat:#"<script type=\"text/javascript\" src=\"//assets.pinterest.com/js/pinit.js\"></script>"];
[htmlString appendFormat:#"</body> </html>"];
return htmlString;
And I have also tried using PinInterest iOS SDK, but all I found is that can only pin the image from url.
And I need to pin image from local bundle image. Any help will be greatly appreciated.
Read the document once, they said Right now, "we only support pinning an image from a url. In the future, we’ll add support for pinning local images." i think this answers your question. for more clarification reed this. hope this helps :)

iOS clickable text inside UITextView

Is there a way to make clickable parts of UITextView. Actually I want to make text something like
By clicking “Register” above, you are agreeing to the Terms of Services and Privacy Statement
where Terms of Services should be one link and Privacy Statement another. And by clicking on those I should do something.
I did it with the code above using this project
- (void)_configureTermsLabel
{
self.termsOfUseLabel.hidden = YES;
self.termsAndConditionsLabel = [[TTTAttributedLabel alloc] initWithFrame:self.termsOfUseLabel.frame];
self.termsAndConditionsLabel.font = [UIFont systemFontOfSize:14];
self.termsAndConditionsLabel.lineBreakMode = UILineBreakModeWordWrap;
self.termsAndConditionsLabel.numberOfLines = 0;
NSString *termsStr = NSLocalizedString(#"Terms of use", #"Terms of use");
NSString *privacyStr = NSLocalizedString(#"Privacy Policy", #"Privacy Policy");
NSString *andStr = NSLocalizedString(#"and", #"and");
NSString *conductStr = NSLocalizedString(#"Code of conduct", #"Code of conduct");
NSString *termsAndConditionsStr = [NSString stringWithFormat:#"%# - %# %# %#", termsStr,
privacyStr, andStr, conductStr];
self.termsAndConditionsLabel.text = termsAndConditionsStr;
NSString *languageCode = [[GLQAppDelegate sharedDelegate] languageIdentifier];
NSURL *termsURL = [NSURL URLWithString:[NSString stringWithFormat:kGLQTermsOfUseURL, languageCode]];
NSURL *privacyURL = [NSURL URLWithString:[NSString stringWithFormat:kGLQPrivacyPolicyURL, languageCode]];
NSURL *conductURL = [NSURL URLWithString:[NSString stringWithFormat:kGLQCodeOfConductURL, languageCode]];
NSRange termsRange = [self.termsAndConditionsLabel.text rangeOfString:termsStr];
NSRange privacyRange = [self.termsAndConditionsLabel.text rangeOfString:privacyStr];
NSRange conductRange = [self.termsAndConditionsLabel.text rangeOfString:conductStr];
[self.termsAndConditionsLabel addLinkToURL:termsURL withRange:termsRange];
[self.termsAndConditionsLabel addLinkToURL:privacyURL withRange:privacyRange];
[self.termsAndConditionsLabel addLinkToURL:conductURL withRange:conductRange];
self.termsAndConditionsLabel.delegate = self;
self.termsAndConditionsLabel.userInteractionEnabled = YES;
[self.scrollView addSubview:self.termsAndConditionsLabel];
}

Resources