Convert URL into hyperlink - ios

I am working on a app in which I am sharing event image with some url
When sharing the event image I am using this content :=
"Hey! I just saw "Venue Name" is having "Event Name" through the XXXX App! We
should check it out. https://app.com/site/redirectlink?event_id=%#"
Now can I make this "https://app.com/site/redirectlink?event_id=%#" link to hyperlink "here"?
I am sharing this content via "UIActivityViewController".
Actually this URL (https://app.com/site/redirectlink?event_id=%#) is used for deep linkling later on when user click this it will be redirect to particular event depend on the event_id.
Instead on the whole URL I want to use here(as hyperlink) only.

might be help you this way..
NSString *url=#"https://app.com/site/redirectlink?event_id=%#";
NSString * title =[NSString stringWithFormat:#"Hey! I just saw \"Venue Name\" is having \"Event Name\" through the XXXX App! We should check it out <html> <body> <a href = '%#'>here</a> </body> </html>",url];
NSArray* dataToShare = #[title];
UIActivityViewController* activityViewController =[[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
activityViewController.excludedActivityTypes = #[UIActivityTypeAirDrop];
[self presentViewController:activityViewController animated:YES completion:^{}];

You may want deep linking for url : projectName://myapp?event_id=12345
Add info.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.erimkurt.projectName</string>
<key>CFBundleURLSchemes</key>
<array>
<string>projectName</string>
</array>
</dict>
</array>
Add appdelegete.m
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
NSLog(#"Calling Application Bundle ID: %#", sourceApplication);
NSLog(#"URL scheme:%#", [url scheme]);
NSLog(#"URL query: %#", [url query]);
return YES;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
if (!url) { return NO; }
UIAlertView *alertView;
alertView = [[UIAlertView alloc] initWithTitle:#"Launch by URL" message:#"This app was launched from a URL" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
NSString *urlString = [url absoluteString];
[[NSUserDefaults standardUserDefaults] setObject:urlString forKey:#"url"];
[[NSUserDefaults standardUserDefaults] synchronize];
return YES;
}
Add viewController.m
NSString *url = [[NSUserDefaults standardUserDefaults] objectForKey:#"url"];
NSLog(#"MYAPPURL: %#",url);

Related

How to share photos to Facebook in Objective-C?

I want to share photos upon my custom button click, am able to share links and messages but when it comes to the sharing of photos am not able to do.
I am using latest Facebook SDK framework (4.15.1).
This is my code in inside the button click.
- (IBAction)btnsharecustom:(id)sender {
//Get aws s3 Image.
NSString* strS3ImageURL = #"https://TEST_IMAGE_URL/1473497380077.jpg";
//Convert to URL.
NSURL* url1 = [NSURL URLWithString:strS3ImageURL];
//Convert it into data.
NSData* data = [NSData dataWithContentsOfURL:url1];
//Convert it to image.
UIImage* image = [UIImage imageWithData:data];
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc]init];
photo.image = image;
photo.caption = #"Test Caption";
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = #[photo];
}
I included this code in app delegate.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
return YES;
}
//FaceBook URLs.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
BOOL handled = [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
];
// Add any custom logic here.
return handled;
}
Also included this code in info.plist
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb15771408xxx409xx</string>
</array>
</dict>
<key>FacebookAppID</key>
<string>15771408xxx409xx</string>
<key>FacebookDisplayName</key>
<string>Cedar iOS</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbapi20160328</string>
<string>fbauth</string>
<string>fb-messenger-api20140430</string>
</array>
When I click upon my custom button Facebook App or safari browser is not launching, so can anyone tell me what I am missing here?
You should present the dialog yourself after modelling the content.
Add this
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:nil];
to the end of your - (IBAction)btnsharecustom:(id)sender method.
Note: It will take time to download your image because it uses synchronous request.
//Convert it into data.
NSData* data = [NSData dataWithContentsOfURL:url1];
Read the documentation here https://developer.apple.com/reference/foundation/nsdata/1547245-datawithcontentsofurl
Do not use this synchronous method to request network-based URLs. For network-based URLs, this method can block the current thread for tens of seconds on a slow network, resulting in a poor user experience, and in iOS, may cause your app to be terminated.
A solution for this problem can be by downloading your image asynchronously before user tap button (if the image to upload is predictable). Usually you can do this in viewDidLoad method. Try this https://github.com/rs/SDWebImage library to make it easy for async request image.
try this code.
- (IBAction)btnsharecustom:(id)sender {
//Get aws s3 Image.
NSString* strS3ImageURL = #"https://placeholdit.imgix.net/~text?txtsize=15&txt=image1&w=120&h=120";
//Convert to URL.
NSURL* url1 = [NSURL URLWithString:strS3ImageURL];
//Convert it into data.
NSData* data = [NSData dataWithContentsOfURL:url1];
//Convert it to image.
UIImage* image = [UIImage imageWithData:data];
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc]init];
photo.image = image;
photo.caption = #"Test Caption";
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = #[photo];
[FBSDKShareAPI shareWithContent:content delegate:self];
;
}
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results{
}
import
// Delegate FBSDKSharingDelegate
-(void)shareImageWithFacebook:(UIImage *)image {
if(![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://"]]) {
//Your device doesn't have Facebook app.
return;
}
FBSDKSharePhoto *photo = [FBSDKSharePhoto alloc];
photo.image = _imageSaved;
[photo setUserGenerated:YES];
photo.caption = AppName;
FBSDKSharePhotoContent *photoContent = [FBSDKSharePhotoContent alloc];
photoContent.photos = #[photo];
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];
dialog.fromViewController = self;
dialog.delegate = self;
dialog.shareContent = photoContent;
[dialog show];
}
pragma mark- FBShareKit Delegate
(void)sharer:(id)sharer didCompleteWithResults:(NSDictionary *)results {
}
(void)sharer:(id)sharer didFailWithError:(NSError *)error {
}
(void)sharerDidCancel:(id)sharer {
}

How to manage openUrl method inside called application in iOS?

I suppose that this is duplicate but I can not figure it out.
I have to call other app from my iOS app using openUrl method. After finishing its work the other app must return to my app using the same method. I figure out how to call the other App and its open my App too. My problem is how to intercept the return to my App. I need to check the value from query string.
I find that method handleOpenURL intercepts return and I can handle my query string.
And here I am stuck - how to use that info inside my ViewController? I set breakpoint in viewDidLoad but it was not hit. Which method I have to use?
EDIT:
My Code is (inside AppDelegate):
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSLog(#"url recieved: %#", url);
NSLog(#"query string: %#", [url query]);
NSLog(#"host: %#", [url host]);
NSLog(#"url path: %#", [url path]);
NSDictionary *dict = [self parseQueryString:[url query]];
NSLog(#"query dict: %#", dict);
return YES;
}
- (NSDictionary *)parseQueryString:(NSString *)query {
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:6];
NSArray *pairs = [query componentsSeparatedByString:#"&"];
for (NSString *pair in pairs) {
NSArray *elements = [pair componentsSeparatedByString:#"="];
NSString *key = [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *val = [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[dict setObject:val forKey:key];
}
return dict;
}
Which works fine.
Inside my ViewController (VC):
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
[self setNeedsStatusBarAppearanceUpdate];
// Instantiate App singleton
singApp = [PESsingApplication sharedInstance];
#try {
// Localize resources using currently saved setting for language
[self setLocalizedResources];
// Init visual buttons
[self baseInit];
// Add code for keyboard management
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardHide:)
name:UIKeyboardWillHideNotification
object:nil];
CGRect screenRect = [[UIScreen mainScreen] bounds];
_screenHeight = screenRect.size.height;
_screenWidth = screenRect.size.width;
}
#catch (NSException *exception) {
[self throwUnknownException:exception];
}
}
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
My url:
URL identifier: xx.mydomain.MyUrlScheme
URL shcemes: MyUrlScheme
I have breakpoints inside my VC (on each of the method shown above).
I use following string to call other app: #"otherApp://openApp?param1=value1&callbackUrl=MyUrlScheme";
They call me from the otherApp using callbackUrl param.
You need to make your own custom URL, please look below
How to implement Custom URL Scheme
Defining your app's custom URL scheme is all done in the Info.plist file. Click on the last line in the file and then click the "+" sign off to the right to add a new line. Select URL Types for the new item. Once that's added, click the grey arrow next to "URL Types" to show "Item 0". Set your URL identifier to a unique string - something like com.yourcompany.yourappname.
After you've set the URL identifier, select that line and click the "+" sign again, and add a new item for URL Schemes. Then click the grey arrow next to "URL Schemes" to reveal "Item 0". Set the value for Item 0 to be your URL scheme name.
Handling Custom URL Calls
In order for your app to respond when it receives a custom URL call, you must implement the application:handleOpenURL method in the application delegate class:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
// your code
}
Parsing the Custom URL
There are several parts to a URL:
scheme://host/path?query
The parts to the URL can be retrieved through the NSURL object that is passed into the application:handleOpenURL method. If you have a fairly simple URL naming scheme and want to allow access to specific pages/keys, you can just use the host name:
Custom URL Value of [url host]:
myapp://page1 page1
myapp://page2 page2
myapp://otherPage otherPage
To pass data into your app, you'll want to use the query string. Here's a simple method for parsing the query string from the url:
- (NSDictionary *)parseQueryString:(NSString *)query {
NSMutableDictionary *dict = [[[NSMutableDictionary alloc] initWithCapacity:6] autorelease];
NSArray *pairs = [query componentsSeparatedByString:#"&"];
for (NSString *pair in pairs) {
NSArray *elements = [pair componentsSeparatedByString:#"="];
NSString *key = [[elements objectAtIndex:0] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *val = [[elements objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[dict setObject:val forKey:key];
}
return dict;
}
Testing The Custom URL
You can easily test your URL scheme in the simulator. Just add a test button to one of your views, and implement the IBAction method for it as follows:
- (IBAction)getTest:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"myappscheme://test_page/one?token=12345&domain=foo.com"]];
}
Then in your app delegate, implement the application:handleOpenURL method:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSLog(#"url recieved: %#", url);
NSLog(#"query string: %#", [url query]);
NSLog(#"host: %#", [url host]);
NSLog(#"url path: %#", [url path]);
NSDictionary *dict = [self parseQueryString:[url query]];
NSLog(#"query dict: %#", dict);
return YES;
}
Finally if you are looking method to receive your data anywhere you can use this two scenario.
You can simple use Local notification or NSUserDefault
NSUserDefault
- (BOOL)application:(UIApplication *)application handleopenURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSUserDefaults *userDefaults=[[NSUserDefaults alloc] init];
[userDefaults synchronize];
NSString *status = [defaults stringForKey:#"any status"];
}
Local notification
- (BOOL)application:(UIApplication *)application handleopenURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.userInfo = [NSDictionary dictionaryWithObjectsAndKeys:VAL, #"value", nil];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
If your viewDidLoad is not called perfectly try in viewWillAppear or viewDidAppear method.
For example purpose:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSDictionary *dict = [self parseQueryString:[url query]];
NSLog(#"query dict: %#", dict);
// add dictionary to standardUserDefaults for saving purpose, like
[[NSUserDefaults standardUserDefaults] setObject:dict forKey:#"DicKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
// add code for navigation/present view controller
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main"
bundle: nil];
YourViewController *yourController = (YourViewController *)[mainStoryboard
instantiateViewControllerWithIdentifier:#"YourViewControllerID"];
self.window.rootViewController = yourController;
return YES;
}
for retrieve
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSMutableDictionary *mutableRetrievedDictionary = [[[NSUserDefaults standardUserDefaults] objectForKey:#"DicKey"] mutableCopy];
// here parse the dictionary and do your work here, when your works is over
// remove the key of standardUserDefaults
[[NSUserDefaults standardUserDefaults] removeObjectForKey:#"DicKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
Store the status from other app in NSUserdefaults, when the ViewController of your app launches fetch the status into a NSString from NSUserdefaults and rise it as an alert.
Call the handleopenURL in appdelegate
- (BOOL)application:(UIApplication *)application handleopenURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSUserDefaults *defaults=[[NSUserDefaults alloc] init];
[defaults synchronize];
NSString *status = [defaults stringForKey:#"status string from other app"];
}

Issue about appStoreReceiptURL

I am trying to convert my paid app to free version with IAP , so basically I need to check if users bought previous version then unlock IAP item , I am not sure I am doing right here or not ! even is it possible to check and track 'appStoreReceiptURL' in development process ? here is my code :
NSURL* url = [[NSBundle mainBundle] appStoreReceiptURL];
NSLog(#"receiptUrl %#",[url path]);
NSError* err = nil;
if (![url checkResourceIsReachableAndReturnError:&err]){
SKReceiptRefreshRequest* request = [[SKReceiptRefreshRequest alloc] initWithReceiptProperties:nil];
request.delegate = self;
[request start];
}
-(void)requestDidFinish:(SKRequest*)request{
if([request isKindOfClass:[SKReceiptRefreshRequest class]]){
NSLog(#"YES, You purchased this app");
}
}
-(void)request:(SKRequest*)request didFailWithError:(NSError *)error{
NSLog(#"NO, you need to buy it ");
}
Now I am able to login with my Apple ID,and after I signed in it tells me YES, You purchased this app", and yes I really bought my app ! , I am going to make sure everything is alright .
Does this process should happen in every update ?
Here is a simple solution
#import <StoreKit/StoreKit.h>
Don't forget to add its delegates
<SKPaymentTransactionObserver, SKProductsRequestDelegate>
Payment Validation
- (IBAction)boughtIt:(id)sender {
NSURL* url = [[NSBundle mainBundle] appStoreReceiptURL];
NSLog(#"receiptUrl %#",[url path]);
NSError* err = nil;
if (![url checkResourceIsReachableAndReturnError:&err]){
SKReceiptRefreshRequest* request = [[SKReceiptRefreshRequest alloc] initWithReceiptProperties:nil];
request.delegate = self;
[request start];
_activity.hidden = NO;
}
}
-(void)requestDidFinish:(SKRequest*)request{
if([request isKindOfClass:[SKReceiptRefreshRequest class]]){
NSLog(#"YES, You purchased this app");
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Congrats !" message:#"Welcome To The World Of Dinosaurs" delegate:self
cancelButtonTitle:#"Cancel" otherButtonTitles:nil, nil];
[alert show];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"isPurchased"];
[[NSUserDefaults standardUserDefaults] synchronize];
_activity.hidden = YES;
[self dismissViewControllerAnimated:YES completion:nil];
}
}
- (void)request:(SKRequest*)request didFailWithError:(NSError *)error{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Sorry !" message:#"It seems you did not purchase this app before, if you like to unlock all content and features please purchase Paleontologist Pack" delegate:self
cancelButtonTitle:#"Cancel" otherButtonTitles:nil, nil];
[alert show];
_activity.hidden = YES;
// [self dismissViewControllerAnimated:YES completion:nil];
NSLog(#"NO, you need to buy it ");
}
This works only if a user PURCHASED the application , it doesn't work for redeem codes

Login with Twitter using Swift and OAuth in ios [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am very new to Swift and IOS. I want to implement the login with twitter account using OAuth in my swift iOS application.
I implemented it but I got
[{“message”:”Could not authenticate you”,”code”:32}]}
error
Yes it is quite heavy to implement OAuth of the twitter to the iOS. In my applications I am using ACAccountStore for authentication with the twitter. For you I can recommend to use this library.
Too Easy
I used framework STTwitter which is very nice. also watch this video Twitter app only Authentication and check STTwitterDemoiOS demo to more clear.
Step 1: Create Twitter app and get Consumer key and Consumer secrete.
Step 2: Download STTwitter Framework and Drag and drop file into your Xcode project.
Step 3: UIWebView/Safari Login
- (IBAction)signInWithTwitterClicked:(id)sender {
//login by website
self.twitter = [STTwitterAPI twitterAPIWithOAuthConsumerKey:CONSUMER_KEY
consumerSecret:CONSUMER_SECRETE];
[_twitter postTokenRequest:^(NSURL *url, NSString *oauthToken) {
NSLog(#"URL: %#", url);
NSLog(#"OauthToken: %#", oauthToken);
// if(1) {
// [[UIApplication sharedApplication] openURL:url];
//} else {
//WebViewVc taken from STTwitterDemoiOS demo.
WebViewVC *webViewVC = [self.storyboard instantiateViewControllerWithIdentifier:#"WebViewVC"];
[self presentViewController:webViewVC animated:YES completion:^{
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webViewVC.webView loadRequest:request];
}];
// }
} authenticateInsteadOfAuthorize:NO
forceLogin:#(YES)
screenName:nil
oauthCallback:#"myapp://twitter_access_tokens/"
errorBlock:^(NSError *error) {
NSLog(#"-- error: %#", error);
// _loginStatusLabel.text = [error localizedDescription];
}];
}
//Step 4 and Step 5 imp to callback to our application
Step 4: Configured info.plist as shown in image.
Step 5: Handle application Delegate method
- (NSDictionary *)parametersDictionaryFromQueryString:(NSString *)queryString {
NSMutableDictionary *md = [NSMutableDictionary dictionary];
NSArray *queryComponents = [queryString componentsSeparatedByString:#"&"];
for(NSString *s in queryComponents) {
NSArray *pair = [s componentsSeparatedByString:#"="];
if([pair count] != 2) continue;
NSString *key = pair[0];
NSString *value = pair[1];
md[key] = value;
}
return md;
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
//Twitter integration
// if ([[url scheme] isEqualToString:#"myapp"] == NO) return NO;
NSDictionary *d = [self parametersDictionaryFromQueryString:[url query]];
NSString *token = d[#"oauth_token"];
NSString *verifier = d[#"oauth_verifier"];
// NSLog(#"Twitter Token=> %#\n Twitter Verifier=>%#",token,verifier);
ViewController *vc = (ViewController *)[[self window] rootViewController];
StartupViewController *startVc=(StartupViewController *)[[vc childViewControllers] objectAtIndex:0];
[startVc setOAuthToken:token oauthVerifier:verifier];
//startVc is my controller where my "Login with twitter" button is there.
//if no Facebook integration then return YES instead if return //[FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
//Facebook Integration
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}
Step 6: Get User credentials.
-(void)setOAuthToken:(NSString *)token oauthVerifier:(NSString *)verifier {
// in case the user has just authenticated through WebViewVC
[self dismissViewControllerAnimated:YES completion:^{
//Dismiss presented controller.
}];
[_twitter postAccessTokenRequestWithPIN:verifier successBlock:^(NSString *oauthToken, NSString *oauthTokenSecret, NSString *userID, NSString *screenName) {
//Here is your Ans.
NSLog(#"SUCCESS screenName: %# ,userID=%#", screenName,userID);
} errorBlock:^(NSError *error) {
NSLog(#"-- %#", [error localizedDescription]);
}];
}
hope this help some one.

iOS custom url scheme

I'm creating an app that uses a custom url scheme, I have it all set up and it works when opening the app up, however, I now want to be able to add a single string to the url so that the person that opens the app can see that string. I'm really struggling with this, can someone help me please?
Here is my code
- (NSDictionary*)parseURLParams:(NSString *)query
{
NSArray *pairs = [query componentsSeparatedByString:#"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs)
{
NSArray *kv = [pair componentsSeparatedByString:#"="];
NSString *val = [[kv objectAtIndex:1]
stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[params setObject:val forKey:[kv objectAtIndex:0]];
}
return params;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Send Challenge"])
{
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:[NSString stringWithFormat:#"I just scored %i points on this great game, called SumsUp. can you beat it?!", gameScore]
title:nil
parameters:nil
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error)
{
// Error launching the dialog or sending the request.
NSLog(#"Error sending request.");
}
else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
// User clicked the "x" icon
NSLog(#"User canceled request.");
}
else
{
// Handle the send request callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:#"request"])
{
// User clicked the Cancel button
NSLog(#"User canceled request.");
}
else
{
// User clicked the Send button
NSString *requestID = [urlParams valueForKey:#"request"];
NSLog(#"Request ID: %#", requestID);
}
}
}
}];
}
I have got the custom url setup in the P-List.
in my app delegate I have:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
UIAlertView *alertView;
NSString *text = [NSString stringWithFormat: #"url recieved: %#", url];
alertView = [[UIAlertView alloc] initWithTitle:#"" message:text delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication withSession:[PFFacebookUtils session]];
}
I hope this makes sense and somebody can help me. If any more information is required please let me know?
Thanks Graham
I had problem with custom URL Scheme on ios v. 9.x.x. when i tried open Youtube URL by App. I have found interesting fact when i have browsed through network.
iOS 9 requires your app to pre-register application schemes it intends to call.
Open your YourApp-Info.plist file and add the key, LSApplicationQueriesSchemes.
List item under LSApplicationQueriesSchemes, add a
new item with the value youtube (in my case).
<key>LSApplicationQueriesSchemes</key>
<array>
<string>youtube</string>
</array>
My solution is simpler. I hope you will find it useful.
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
// Example URL: myapp://myapp.com/showString/yourString
BOOL isMyAppURL = [[url scheme] isEqualToString:#"myapp"];
if (isMyAppURL)
{
NSArray* pathComponents = [url pathComponents];
NSString *command = pathComponents[0];
// Check for showString command.
if ([command isEqualToString:#"showString"])
{
NSString *stringToShow = [pathComponents[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"String to show: %#", stringToShow);
}
}
return isMyAppURL;
}
This should point you to the right direction.

Resources