Tag: appdelegate

如何将数据从AppDelegate传递给ViewController?

我正在使用Safari来浏览网页。 当我点击这个页面上的button后,我的Ipad将启动我的应用程序。 所以我实现了方法- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url在AppDelegate.m – (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url 。 – (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url{ if (!url) { return NO; } NSString *URLString = [url absoluteString]; self.paramArray = [URLString componentsSeparatedByString:@"@"]; NSLog(@"%d",[self.paramArray count]); for (int i = 1; i < [self.paramArray count]; i++) { NSLog([self.paramArray objectAtIndex:i]); } return YES; } 我在网页上使用的url是myapp://@first_part@second_part@third_part 。 self.paramArray存储url的子串( […]

如何使用AppDelegate在视图之间共享iAd横幅

我期待在我的应用程序中实现iAd。 到目前为止,我已经设法让他们正确显示/解雇在每个视图使用下面。 应用程序代表: import UIKit import iAd @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? var adBannerView = ADBannerView() 视图控制器1: import UIKit import iAd class HomeScreenViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, ADBannerViewDelegate { let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate //Creates reference to the AppDelegate override func viewDidLoad() { super.viewDidLoad() loadAds() } func loadAds(){ self.appDelegate.adBannerView.removeFromSuperview() self.appDelegate.adBannerView.delegate = […]

从视图控制器调用应用程序委托方法

我想知道是否可以从另一个ViewController调用应用程序委托方法。 当应用程序启动时, application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool i方法被调用。 我可以从另一个视图控制器第二次调用这个方法吗?

为什么我得到延迟加载NSBundle MobileCoreServices.framework?

当我从主viewControllerredirect到另一个viewController我得到这个 错误: 延迟加载NSBundle MobileCoreServices.framework, 加载MobileCoreServices.framework, systemgroup.com.apple.configurationprofilespath的系统组容器path为/ Users / develop / Library / Developer / CoreSimulator / Devices / 083C0102-C85F-463A-96F4-CA1B9AC7919D / data / Containers / Shared / SystemGroup / systemgroup.com.apple。 configurationprofiles 我的代码是… Appdelegate.m if (![[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"]) { [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"]; [[NSUserDefaults standardUserDefaults] synchronize]; NSLog(@"Launched first time"); } else { NSLog(@"Already launched"); [self getData]; } […]

APPDelegate中的openURL转换错误NSString – > String(Swift和iOS8)

我目前正在开发一个整合了Facebook的iOS应用程序,而我在使用Swift(使用ObjC时没有任何问题)进行调查时遇到了一些问题。 事情是,这是从另一个应用程序(在这种情况下,在Web浏览器中的FB)来appDelegate中执行的方法: func application( application: UIApplication, openURL url: NSURL, sourceApplication: NSString, annotation: AnyObject) -> Bool { let appString : String = sourceApplication as String // Try to convert format => EXCEPTION let appString : String = String(sourceApplication) // 'SSS' Suggestion: EXCEPTION println(sourceApplication) // Try to print the value => EXCEPTION return FBAppCall.handleOpenURL(url, sourceApplication:sourceApplication, withSession:session) // […]

在ios8中使用appdelegate暂停spritekit游戏

我在我的游戏中有一个暂停菜单,当我点击主页button时,我想要切换。 当我在我的游戏中时,它是有效的,但是当我点击主页button时,菜单出现了,但游戏不会暂停。 当我重新启动应用程序时,菜单仍然存在,但是游戏不会暂停。 看起来像spritekit会自动暂停并重新启动游戏,当你离开并进入应用程序。 当我在应用程序内,我完全控制它。 但是当我退出/进入应用程序时,它的行为如何。 有什么build议么? func applicationWillResignActive(application: UIApplication!) { // get the root viewcontroller // toggle my pausemenu method. pause menu sets skview.paused = true }

AppDelegate和ViewController类的iOS区别

如何知道AppDelegate类中的代码以及ViewController类中的代码。 这两个类在UIViewController和applicationDidFinishLaunching:都有类似的方法viewDidLoad applicationDidFinishLaunching:在UIApplicationDelegate 。 我猜applicationDidFinishLaunching:会先被调用,这就是你创build视图的地方。 但是有人能解释一下这些类中的通用代码吗?

在swift中configuration深层链接?

所以我有一个用swift编写的应用程序,我想使用深层链接。 用户可以点击一个URL的路线中有不同的信息,如post的ID或喜欢的数量等等。 我明白,你把这个在AppDelegate中: func application(application: UIApplication,openURL url: NSURL,sourceApplication sourceApplication: String?,annotation annotation: AnyObject?) -> Bool { println(url.host as String!) return true } 并且在appname://之后打印所有内容。 但是我怎么能得到url.host我的视图控制器被分析成我需要的信息。 如果URL的声明超出了那个函数,那么我可以使用这个: let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate let InfoFromDeepLink = appDelegate.url.host 但是由于它是庞大的Objective-C函数的内部,所以我很无奈。 你怎么做到这一点? 我完全困惑。 我甚至不能设置函数return url.host因为它不允许。 这就是我会在Javascript中做的。 如果你也知道Javascript也许把它放在一个Web开发人员会理解,因为我很新。 对于Swift开发人员来说,这必须如此简单吗? 我觉得很愚蠢

如何从其他ViewController中更改AppDelegate中的RootViewController?

这是AppDelegate中的didFinishLaunchingWithOptions方法。 让我解释一下情况,我已经在我的应用程序中开发了像facebook一样的sideMenu,但现在我必须根据屏幕(ViewController)更改sideMenu列表, 这里的Side菜单是SideMenuViewController,它是一个包含的参数,最终成为窗口的rootViewController。 所以,最基本的问题就是“如何更改成为windows的rootViewController的控制器或variables” – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; SideMenuViewController *leftMenuViewController = [[SideMenuViewController alloc] init]; self.container = [ContainerOfSideMenuByVeerViewController containerWithCenterViewController:[self navigationController] leftMenuViewController:leftMenuViewController]; self.window.rootViewController = self.container; [self.window makeKeyAndVisible]; return YES; } 如果任何程序员想知道更多的代码或需求,我很欢迎通过编辑我的代码或评论。

iPhone registerForRemoteNotificationTypes不会产生错误,但不会触发授予设备令牌的委托

我正在开发一个需要推送通知的iPhone应用程序。 我遵循了创buildauthentication和修改应用程序ID的说明。 我不完全肯定我做了这个正确的,但我确实按照方向。 任何想法如何我可以检查,看看这是否可以吗? 当我在模拟器中运行时,我收到一条错误消息,说模拟器不支持推送通知。 这是有点期待。 顺便说一句:我在这里似乎有这个问题几次。 它似乎总是与一个监狱破碎的电话。 我的手机没有被监禁。 但是当我在iPhone上debugging时,didRegisterForRemoteNotificationsWithDeviceToken方法永远不会被触发。 我真的很感激一些帮助。 我的代码如下。 -(void)applicationDidFinishLaunching:(UIApplication *)application { rootController.delegate = self; [window addSubview:rootController.view]; [window makeKeyAndVisible]; [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; } – (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { NSString *str = [NSString stringWithFormat:@"%@",deviceToken]; NSLog(str); } – (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { NSString *str = [NSString stringWithFormat: […]