Image copying to pasteboard in ios - ios

I am having an app in which I want to copy an image and paste it in the sms app.
I am using the below code.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *filePath = [[NSBundle mainBundle]pathForResource:#"Heritage" ofType:#"png"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
[pasteboard setData:data forPasteboardType:#"public.png"];
}
I have got this code after searching on google and there are lots of code but somehow none of them seems to work for me.
When I run the app and go to sms app and press, the paste option doesn't show me there.
Heritage.png is an image in my app's bundle.
Where am I doing any mistake?
Please let me know.
Thanks...

Finally, I got a solution of my own.
I didn't enable the keyboard extension to allow full access.
Just forgot to set "RequestOpenAccess" to "YES".
Hope someone else does not forget to check this small things.
Thanks...

Related

iOS show webview offline with images

I am trying to download a webpage (html) then display the local html that has been downloaded in a UIWebView. It is working, but the offline UIWebView doesn‘t show me the images.
This is my code:
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [NSString stringWithFormat:#"%#/%#", [paths objectAtIndex:0],#"index.html"];
NSURL *url = [NSURL URLWithString:#"https://www.mypage.com"];
NSData *urlData = [NSData dataWithContentsOfURL:url];
[urlData writeToFile:filePath atomically:YES];
[Website loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#end
Can anyone share some sample code to add the website content (the images)?
Any help would be appreciated. Thanks!
Most likely the HTML references images that you aren't also downloading. The first step would be to parse the HTML and download the images too. Then you may need to fix the local copy of HTML if the image references aren't relative to the base document. For example, if they refer to images on a different server, you'll have to fix those links internally. And if the original document uses Javascript to load images dynamically, it may never work the way you want.

How can I set image in textDocumentProxy with custom keyboard extension iOS 8?

How can we set an image behalf of the text?
Following code is to display text in the input view:
[self.textDocumentProxy insertText:[key currentTitle]];
My code of paste board to display the image :
NSData *imgData = UIImagePNGRepresentation(image);
[pasteBoard setData:imgData forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]];
NSString* newStr = [[NSString alloc] initWithData:imgData encoding:NSUTF8StringEncoding];
[self.textDocumentProxy insertText:[pasteBoard string]];
I have created a pasteboard with the images just I have to display the images in to input view.
See this picture for the concept :
Note:
I have to select image from keyboard and show in inputview not to copy paste from library.
If anyone know please reply as answer or any suggestion will also acceptable.
Thanks!
I don't think it's possible to add directly an image from a custom keyboard. A workaround would be to copy the image to the pastboard and paste it in the destination area. (It's not very nice but It's the only way I see actually)
I have get solution for this question use clipboard copy and paste
Code :
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
NSData *data = [self.Videoassets objectAtIndex:btn.tag];
NSLog(#"File size is : %.2f MB",(float)data.length/1024.0f/1024.0f);
[pasteBoard setData:data forPasteboardType:#"public.mpeg-4"];

How do I send audio file send via iMessage ios 8

As we know with the launch of ios 8 the apple allow custom Keyboard extension.In keyboard extension we can send images,gif etc in SMS by using Copy image to clipboard.code
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSData *data= UIImagePNGRepresentation([UIImage imageNamed:#"so_close_disappointed_meme.png"]);
[pasteboard setData:data forPasteboardType:#"public.png"];
Now i am trying to send audio file in iMessage like this feature reference.don't know apple will allow us to send audio in iMessage?.so for i tried above approach but it did not show any paste option for audio in SMS window.
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSString *path = [[NSBundle mainBundle] pathForResource:#"tune"ofType:#"mp3"];
NSURL *url = [[NSURL alloc] initWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
[pasteboard setData:data forPasteboardType:#"public.mp3"];
Any one can suggest me how do we send audio file by using custom keyboard extension.is it possible?
I believe you could directly attach the file to MFMessageComposeViewController. Here is the documentation link of how it could be done.
Following would be the steps to do so.
Check if file can be send using file UTI using +
(BOOL)isSupportedAttachmentUTI:(NSString *)uti
Find File UTI. i.e. path for the file
Attach file to MFMessageComposeViewController using -
(BOOL)addAttachmentData:(NSData *)attachmentData
typeIdentifier:(NSString *)uti filename:(NSString *)filename
As the description for the method says
This method is especially useful when the attachment you want to add to a message does not have a file system representation. This can be the case, for example, for programmatically composed audiovisual content.
Note : You will have to convert audio file to NSData
The MFMessageComposeViewController isn't the solution in this scenario. A custom keyboard extension shouldn't present a new view controller, rather just paste the audio file to the pasteboard. Heres some swift code that worked for me
let path = NSBundle.mainBundle().pathForResource("audio", ofType:"wav")
let fileURL = NSURL(fileURLWithPath: path!)
let data = NSData(contentsOfURL: fileURL)
let wavUTI = "com.microsoft.waveform-audio"
UIPasteboard.generalPasteboard().setData(data!, forPasteboardType: wavUTI)

Check on app resume for server file changes?

I have a Data plist (conveniently named Data.plist) that is updated on launch of the app:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Determile cache file path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [NSString stringWithFormat:#"%#/%#", [paths objectAtIndex:0],#"Data.plist"];
NSString *dataURLString = #"http://link/to/Data.plist";
NSURL *dataURL = [[NSURL alloc] initWithString:dataURLString];
NSData *plistData = [NSData dataWithContentsOfURL:dataURL];
[plistData writeToFile:filePath atomically:YES];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:filePath];
NSLog(#"The bundle is %#", filePath);
self.data = dict;
// Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
return YES;
}
I'd like to be able to have some way of checking the saved plist against the server plist - I've seen some implementations that use external libraries but there has to be something in the original iOS SDK. Any ideas? I've read whatever code I do end up using needs to be implemented in viewWillAppear but I'm not sure what that code is exactly.
Two things... first, dataWithContentsOfURL: and generally any of Apple's (temptingly convenient) <anything>WithContentsOfURL: methods are extremely unsafe in the real world. It's blocking which means that no other code will execute until your request succeeds or fails. That means that if the server isn't available or your device doesn't have internet or for some other reason cannot retrieve your data, your phone will sit there until either the iOS watchdog process kills your app for freezing for too long, or it just fails. Then the rest of your app that is expecting data will freak out because suddenly you have no data when your code assumes you should. This is one of many problems with synchronous requests.
I won't go into how to implement asynchronous requests, but head over to Apple's documentation or you can use a wrapper framework like http://allseeing-i.com/ASIHTTPRequest/ that does it for you. Also have a look at http://www.cocoabyss.com/foundation/nsurlconnection-synchronous-asynchronous/
To answer your actual question, you could have a tiny text file on your server with a version number or time stamp and download that along with your plist. on subsequent launches, you can pull down the time stamp/version number and compare it against the one you've got stored, and if the version on the server is more recent, then you pull it and save the new time stamp/version number.

IBAction Open Local HTML File

I've got a view based application that one is at last just a single WebView ... with a Tabbar with some Icons.
So i need to add a small icon for go back to the localHTML File home.html.
Maybe could someone give me some informations how to handle it without change the view to a new one?
Here is how my other IBActions looks like
- (IBAction)news_button:(id)sender; {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"http://www.google.com"]];
}
Other option could be open a Website but not in safari ... like it does at the moment.
Thanks for sharing! :)
With the line above you are opening it in Safari right now.
You can get path to the local file if it is in main bundle catalog with
NSString *filePath = [[NSString stringWithFormat:#"%#/%#", [[NSBundle mainBundle] resourcePath], #"home.html"] retain];
So why not use
[yourWebView loadRequest:[NSURLRequest initWithURL:[NSUrl initWithString:filePath]]];

Resources