Custom Actions for Custom URL Schemes Mac Objective-c [duplicate] - objective-c

This question already has answers here:
How to handle with a default URL scheme
(5 answers)
Closed 9 years ago.
how can I make it so that if the URL is myapp://foo that it will preform an action and if it is myapp://bar it will preform a different action.
I've gotten this far with my other question here
Help is very much appreciated.

Once you have your URL scheme registered inside your application, you should be able to capture the URL used to open your application with something like this
- (void)handleURLEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent {
NSString *calledURL = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSLog(#"%#", calledURL);
// Split and do something with calledURL
}
Once you have that URL you should easily be able to split it and determine what you want to do.
There is another question on exactly this as well.

Related

iOS 9 Universal Links - no parameters recieved

Using the new iOS 9 feature - Universal links, from my understanding, is supposed top open my app whenever a specific domain is opened in browser (or other apps?). I have gone through the documentation and through this guide.
However, when the app opens I do not receive the parameter that is meant to help me open the correct page for the user to view....
I would share the code I'm using, but it's quite a big infrastructure and not really a couple of lines of code (server side JSON, plist rows and some IDs on the developer portal).
Anyone encountered it and could give me a hand here, please?
The Branch guide you linked to (full disclosure: I work with the Branch team) unfortunately doesn't cover a rather important step: what to do after your app opens. Which is exactly the issue you're encountering :). But the good news is you've already done the hard part with all the server and entitlement config.
What you need to complete the loop is a continueUserActivity handler in your AppDelegate.m file. This will pass you a webpageURL property containing the actual URL of the Universal Link that opened your app, which you can then parse and use for routing. It'll look something like this:
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *))restorationHandler {
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
NSString *myUrl = [userActivity.webpageURL absoluteString];
// parse URL string or access query params
}
return YES;
}
Also, when testing keep in mind that Universal Links unfortunately don't work everywhere yet:
P.S., gotta ask...since you found the Branch blog already, had you considered using the service to handle the link routing for you? It can definitely help simplify things!

Pulling usable text from URL like Pocket and Instapaper

I know that this question has been posed for C# and possibly other languages but I haven't found one for Objective-C (Xcode)
The C# question can be found here C# Version
Im looking to be take any URL (NSURL or NSString) and convert that webpages contents into.
1) The Title of that webpage (New article title)
2) The Image for that article (First major image)
3) The Article text itself (Pure text, no ads)
Those are the 3 major things. Id also like to have the
1) Author
2) Date Updated
3) Website that posted the article
but those are not as important.
The way I have my code set up to parse the actual article (which doesn't do the job I want exactly) is:
- (void)viewDidLoad {
[super viewDidLoad];
NSURLRequest *request = [NSURLRequest requestWithURL:finalUrl];
[self.webview loadRequest:request];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
NSString *fullArticle = [self.webview stringByEvaluatingJavaScriptFromString:#"document.body.innerText"];
self.story.text = fullArticle;
NSLog(#"Article: %#",fullArticle);
}
finalUrl being a NSURL variable.
The NSLog shows all the text from the inner body of the webpage but includes a lot of extra "garbage" that I don't want, It also doesn't give back the title, images or anything else that I wanted.
So how can this be done in objective-C? I know that Pocket does it very well in there app.
Readability.com has an incredible API that allows for this.
Its called the Parser API.
Steps:
Create an account on readability
Go to the Developer section
Generate Tokens
Use readability API url with your token and the URL you would like to parse.
It will return a HTML page filled with everything you want.

Observe all property changes of object [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Observing a Change to ANY Class Property in Objective-C
I have a object currentUser which contains ints and const char*s and I am trying to implement a logout system. When the logout button is pressed, I want to be able to check if I have made any changes to the object and if so, I want to prompt the user to save before logging out.
In order to do so I think I need to be able to observe the changes, if any, that are made to the object. I considered KVO but I don't know how to observe the entire variable as a key path. Does anybody have any ideas on what I should do? Also if you could post some code as well that would help!
Not sure if this fits your needs but would posting a notification to NSNotificationCenter work?

Custom Finder (folder) Image w/ Cocoa [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Using Cocoa to create an icon for a folder
I'm trying to set a custom folder image, but only with cocoa, as dropbox:
But I realized that this isn't really simple.
Anyone with some solution/tip?
Use - (BOOL)setIcon:(NSImage *)image forFile:(NSString *)fullPath options:(NSWorkspaceIconCreationOptions)options method of NSWorkspace Class.

UIWebView capture post

I am looking for a starting point on a project that needs to display a UIWebView on an iPad. THe catch is that the HTML will be generated by the pad and displayed in the UIWebView, and will contain many input controls.
What is needed is a way to grab the contents of these controls after the user has completed entry similar to how I would do it on a server. I need to grab this entered data on the iPad without an actual submit.
Does anyone know the starting point for this type of interaction?
You can do this by implementing the UIWebViewDelegate delegate's shouldStartLoadWithRequest method:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSData* data = request.HTTPBody;
NSString* s = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if([s length] == 0)
return YES;
else
return NO;
}
It works fine with a post.
Within the previously posted article it also mentioned the UIWebViewDelegate method,
webView:shouldStartLoadWithRequest:navigationType:
This gets invoked on the delegate before a link is followed. I haven't tried it, but this method might be invoked when submitting the form. Use a GET method. Easier than having to loop out of the app and back.
It can be done in simple way..
we know HTTP request contains -
Method (GET,POST..etc)
HTTP header
HTTP body
we can check header field value for Conent-type if it is x-www-form-urlencoded
then form field values are sending thru them as key=value pairs
then we can catch therse paires in
webView:shouldStartLoadWithRequest:navigationType: - in request parameter as
[request HTTPBody], similarly we can get method [HTTPMethod]..etc
if it is simply GET method then all pairs will be in request itself.
:) hope it helps
Here's a way to do it:
Register a custom URL scheme for your App (see here f.e. http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html)
When the user touches your save/submit/whatever button you read out the values of all needed form-fields, construct a url that matches your URL scheme and redirect to this URL with JavaScript (window.location) and work with the data in Objective-C and do what you have to do.
Example URL could be: myapp://value_of_field1/value_of_field2/...
See the linked tutorial on how to register a custom scheme and how to retrieve the data in Obj-C.