0

i am new to ios and objected C.

I am trying to encode a url, bit i am getting the error

/Users/zupportdesk/Desktop/MyIOSApps/ZDticketSystem/ZDticketSystem/ViewController.m:313:52: No visible @interface for 'NSString' declares the selector 'URLEncodeUsingEncoding:'

#import "ViewController.h"
#import "AppDelegate.h"
#import "ApplicationEnvironmentURL.h"
#import "AFNetworking/AFNetworking.h"
#import "HHAlertView/HHAlertView.h"
#import "MBProgressHUD/MBProgressHUD.h"
#import "AppDelegate.h"


@interface ViewController ()<UITextFieldDelegate, UIActionSheetDelegate> {
    ApplicationEnvironmentURL *applicationEnvironment;
    NSString *BASEURL;
    NSString *global_profileId;
    AppDelegate *delegate;
}

@property (nonatomic, strong) NSString *username;
@property (nonatomic, strong) NSString *password;
@end

@implementation ViewController
--- defaults methods here

- (void)setupProfileidURL:(NSString *)profileToken {
    NSString *encoded_profileToken = [profileToken URLEncodeUsingEncoding:NSUTF8StringEncoding];
    NSString *user_login_url = [applicationEnvironment get_user_api_url];
    BASEURL = [[user_login_url stringByAppendingString:@"Account/GetProfileDetails?profileToken="] stringByAppendingString:encoded_profileToken];
    NSLog(@"Base URL: %@", BASEURL);
}

I am calling the method like this [self setupProfileidURL:profileToken];

View Holder header file

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UITextField *tv_username;
@property (weak, nonatomic) IBOutlet UITextField *tv_password;

@end

I want to implement this https://madebymany.com/blog/url-encoding-an-nsstring-on-ios . can some one help me with this url encoding.

Sathya Baman
  • 3,424
  • 7
  • 44
  • 77
  • 2
    You have to create a category for `NSString` that implement `-URLEncodeUsingEncoding:` and import that category where you need it. See there on how to create a category: http://stackoverflow.com/questions/24324021/how-do-i-create-a-category-in-xcode-6-and-7 – Larme Oct 26 '16 at 10:24

1 Answers1

2

You are getting this message

No visible @interface for 'NSString' declares the selector 'URLEncodeUsingEncoding:'

because URLEncodeUsingEncoding is a method which is defined in a Category and you are not using that category in your class thats why you are getting this message.

Also CFURLCreateStringByAddingPercentEscapes is deprecated from iOS so in place of it you can use stringByAddingPercentEncodingWithAllowedCharacters

Below is an example of of your function

- (void)setupProfileidURL:(NSString *)profileToken {
    NSString *encoded_profileToken = [profileToken stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    NSString *user_login_url = [applicationEnvironment get_user_api_url];
    BASEURL = [[user_login_url stringByAppendingString:@"Account/GetProfileDetails?profileToken="] stringByAppendingString:encoded_profileToken];
    NSLog(@"Base URL: %@", BASEURL);
} 

Also as per the @Larme comment you can create a category and use it in your application by importing it.

Rajat
  • 10,977
  • 3
  • 38
  • 55