Arp*_*ekh 1 iphone cocoa-touch objective-c ios xcode6
所有.在我的iOS应用程序中.在我的许多页面上Too many alerts and also with many Network conditions.
有太多警报文本,我厌倦了.每次我必须使用相同的代码.
我可以在某个帮助程序类中声明此代码吗?或者重复使用此代码?
-(BOOL)checkInternetAndlocationServices {
if(IS_INTERNET) {
if([CLLocationManager locationServicesEnabled] &&
[CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied){
return YES;
}
else
{
NSLog(@"Location services are disabled.");
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Location services are off." message:@"This app requires an Location services." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Location Services", nil];
[alert setTag:NO_LOCATIONSERVICES];
[alert show];
return NO;
}
}
else
{
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Internet connection is off." message:@"This app requires an internet connection and locations services, please enable internet connection and location services." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Settings", nil];
[alert setTag:NO_INTERNET];
[alert show];
return NO;
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢.如果您发现它有用,请编辑此问题.
感谢您提供良好的方法,还有其他任何方式,最受欢迎的例子.
@implementation UIAlertView (MyAlert) +(void) showAlertWithTitle:(NSString *)title message:(NSString *)message { [[[UIAlertView alloc] initWithTitle:title message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; } @end
#define Alert(title,msg,target) [[[UIAlertView alloc] initWithTitle:title message:msg delegate:target cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show] Alert(@"This is Title",@"This is message",self);
归档时间: |
|
查看次数: |
268 次 |
最近记录: |