appdelegate 设置

本文介绍了iOS应用如何设置启动画面并记录用户登录信息,同时展示了如何判断用户是否首次使用应用。此外,还详细说明了应用内社会化分享的配置过程及消息推送的初始化设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


//禁止横屏


-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{


    return UIInterfaceOrientationMaskPortrait;


}




- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


    


    //欢迎页显示3


    [NSThread sleepForTimeInterval:2.0];


    


    //纪录用户登录信息


    [[[CommenData alloc]init] gatherMessage];


    


    //纪录判断用户是否首次打开


    NSUserDefaults *userDefaults=[NSUserDefaults standardUserDefaults];


    if (![userDefaults boolForKey:@"firstLoad"]) {


        UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];


        WelcomeViewController *w=[story instantiateViewControllerWithIdentifier:@"firstPage"];


        self.window.rootViewController=w;


        [userDefaults setBool:YES forKey:@"firstLoad"];


        [userDefaults synchronize];


        


    }


    


    


    //初始化社会化分享


    [ShareSDK registerApp:@"45df0da85a70"];


    //


    //        //添加新浪微博应用 注册网址 http://open.weibo.com


    //        [ShareSDK connectSinaWeiboWithAppKey:@"568898243"


    //                                   appSecret:@"38a4f8204cc784f81f9f0daaf31e02e3"


    //                                 redirectUri:@"http://inav.int-yt.cn"];


    //添加QQ应用  注册网址  http://open.qq.com/


    [ShareSDK connectQQWithQZoneAppKey:@"1102001449"


                     qqApiInterfaceCls:[QQApiInterface class]


                       tencentOAuthCls:[TencentOAuth class]];


    


    //添加微信应用 注册网址 http://open.weixin.qq.com


    NSString *appId = @"wx659eb9e9ffd5abc4";


    [ShareSDK connectWeChatSessionWithAppId: appId wechatCls:[WXApi class]];


    


    


    // 初始化消息推送


#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1


    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {


        //可以添加自定义categories


        [APService registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge |


                                                       UIUserNotificationTypeSound |


                                                       UIUserNotificationTypeAlert)


                                           categories:nil];


    } else {


        //categories 必须为nil


        [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |


                                                       UIRemoteNotificationTypeSound |


                                                       UIRemoteNotificationTypeAlert)


                                           categories:nil];


    }


#else


    


    //categories 必须为nil


    [APService registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |


                                                   UIRemoteNotificationTypeSound |


                                                   UIRemoteNotificationTypeAlert)


                                       categories:nil];


#endif


    // Required


    [APService setupWithOption:launchOptions];


    [APService setBadge:0];


    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0 ];


    NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];


    NSString *pushStatus = [defaults objectForKey:@"status"];//根据键值取出status


    if([pushStatus isEqualToString:@"off"]){


        [[UIApplication sharedApplication] unregisterForRemoteNotifications];


    }


    


    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];


    [defaultCenter addObserver:self selector:@selector(networkDidReceiveMessage:) name:kJPFNetworkDidReceiveMessageNotification object:nil];


    


    


    return YES;


}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值