'NSString' 没有可见的@interface 声明选择器 URLEncodeUsingEncoding
No visible @interface for 'NSString' declares the selector URLEncodeUsingEncoding
我是ios的新手,反对C.
我正在尝试对 url 进行编码,但是我遇到了错误
/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);
}
我是这样调用方法的
[self setupProfileidURL:profileToken];
查看Holder头文件
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *tv_username;
@property (weak, nonatomic) IBOutlet UITextField *tv_password;
@end
我想实现这个 https://madebymany.com/blog/url-encoding-an-nsstring-on-ios。谁能帮我解决这个 url 编码问题。
您正在收到此消息
No visible @interface for 'NSString' declares the selector
'URLEncodeUsingEncoding:'
因为 URLEncodeUsingEncoding
是在类别中定义的方法,而您没有在 class 中使用该类别,这就是您收到此消息的原因。
另外 CFURLCreateStringByAddingPercentEscapes
已从 iOS 中弃用,因此您可以使用 stringByAddingPercentEncodingWithAllowedCharacters
代替它
下面是您的函数的示例
- (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);
}
另外,根据@Larme 的评论,您可以创建一个类别并通过导入在您的应用程序中使用它。
我是ios的新手,反对C.
我正在尝试对 url 进行编码,但是我遇到了错误
/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);
}
我是这样调用方法的
[self setupProfileidURL:profileToken];
查看Holder头文件
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UITextField *tv_username;
@property (weak, nonatomic) IBOutlet UITextField *tv_password;
@end
我想实现这个 https://madebymany.com/blog/url-encoding-an-nsstring-on-ios。谁能帮我解决这个 url 编码问题。
您正在收到此消息
No visible @interface for 'NSString' declares the selector 'URLEncodeUsingEncoding:'
因为 URLEncodeUsingEncoding
是在类别中定义的方法,而您没有在 class 中使用该类别,这就是您收到此消息的原因。
另外 CFURLCreateStringByAddingPercentEscapes
已从 iOS 中弃用,因此您可以使用 stringByAddingPercentEncodingWithAllowedCharacters
下面是您的函数的示例
- (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);
}
另外,根据@Larme 的评论,您可以创建一个类别并通过导入在您的应用程序中使用它。