iOS-UIApplication sharedApplication 的常用使用方法

释放双眼,带上耳机,听听看~!
//设置icon上的数字
    [UIApplicationsharedApplication].applicationIconBadgeNumber = 4;


//设置摇动手势的时候,是否支持redo,undo操作
    [UIApplicationsharedApplication].applicationSupportsShakeToEdit =YES;


//判断程序运行状态
    /*
     UIApplicationStateActive
     UIApplicationStateInactive
     UIApplicationStateBackground
     */

   if([UIApplicationsharedApplication].applicationState ==UIApplicationStateInactive){
        NSLog(@"程序在运行状态");
    }
    

//阻止屏幕变暗进入休眠状态
    [UIApplicationsharedApplication].idleTimerDisabled =YES;
    

//显示联网状态
    [UIApplicationsharedApplication].networkActivityIndicatorVisible =YES;


//在map上显示一个地址,其实就是利用了openURL这个方法

   NSString* addressText =@"1 Infinite Loop, Cupertino, CA 95014";

   // URL encode the spaces

    addressText =  [addressTextstringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

   NSString* urlText = [NSStringstringWithFormat:@"http://maps.google.com/maps?q=%@", addressText];

    [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:urlText]];


//发送电子邮件,也是利用openURL

   NSString *recipients =@"mailto:first@example.com?cc=second@example.com,third@example.com&subject=Hello from California!";

   NSString *body =@"&body=It is raining in sunny California!";

    NSString *email = [NSStringstringWithFormat:@"%@%@", recipients, body];

    email = [emailstringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:email]];
    

//打电话到一个号码,依然是利用openURL

    // Call Google 411
    [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"tel://8004664411"]];


//发送短信,万能的openURL啊

    // Text to Google SMS
    [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"sms://466453"]];


//打开一个网址,openURL的常规操作

   // Lanuch any iPhone developers fav site
    [[UIApplicationsharedApplication]openURL:[NSURLURLWithString:@"http://itunesconnect.apple.com"]];



 

人已赞赏
iOS文章

iOS使用核心的50行代码实现一个路由组件

2019-9-28 11:58:40

iOS文章

iOS-定位功能

2019-9-28 12:45:58

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索