【问题标题】:Unable to build Facebook SDK for iOS on Xcode8无法在 Xcode8 上为 iOS 构建 Facebook SDK
【发布时间】:2017-06-22 19:26:44
【问题描述】:

我第一次尝试添加 Facebook 分析,但在 Objective C 项目中遇到此错误

使用未声明的标识符“applicationDidBecomeaAtive”

我的步骤: 1- 复制 Bolts.framework 和 FBSDKCoreKit.framework

2- 复制到 AppDelegate.m

#import <FBSDKCoreKit/FBSDKCoreKit.h>

3- 但是这些行中的错误

    - (void)applicationDidBecomeActive:(UIApplication *)application {
        [FBSDKAppEvents activateApp];
    }

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        [[FBSDKApplicationDelegate sharedInstance] application:application
                                 didFinishLaunchingWithOptions:launchOptions];
        return YES;
    }

    - (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
    return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                          openURL:url
                                                sourceApplication:sourceApplication
                                                       annotation:annotation];
}

【问题讨论】:

    标签: ios xcode8 fbsdk


    【解决方案1】:
    //
    //  AppDelegate.m
    //  myappgames
    //
    //  Created by Vishal on 9/10/15.
    //  Copyright (c) 2015 Vishal. All rights reserved.
    //
    
    #import "AppDelegate.h"
    #import "UIDevice+Res.h"
    #import <FBSDKCoreKit/FBSDKCoreKit.h>
    
    
    
    @interface AppDelegate ()
    
    @end
    
    @implementation AppDelegate
    @synthesize navigationObj;
    @synthesize bannerViewAdUnitID,InterstitialAdUnitID;
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        [[FBSDKApplicationDelegate sharedInstance] application:application
                                 didFinishLaunchingWithOptions:launchOptions];
        //--------Admob Ids---------
        bannerViewAdUnitID = @"ca-app-pub-00000";
    
        //--------InterstitialAd Ids---------
        InterstitialAdUnitID = @"ca-app-pub-00000000";
    
    
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            self.viewcontroller = [[ViewController alloc] initWithNibName:@"ViewController_IPad" bundle:nil];
            navigationObj = [[UINavigationController alloc]initWithRootViewController:self.viewcontroller];
            self.window.rootViewController = navigationObj;
        } else {
            self.viewcontroller = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
            navigationObj = [[UINavigationController alloc]initWithRootViewController:self.viewcontroller];
            self.window.rootViewController = navigationObj;
        }
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    
    
    - (void)applicationDidBecomeActive:(UIApplication *)application
    {
        [FBSDKAppEvents activateApp];
    }
    
    
    
        - (BOOL)application:(UIApplication *)application
    openURL:(NSURL *)url
    sourceApplication:(NSString *)sourceApplication
    annotation:(id)annotation {
        return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                              openURL:url
                                                    sourceApplication:sourceApplication
                                                           annotation:annotation];
    }
    
    
    - (void)applicationWillResignActive:(UIApplication *)application
    {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }
    
    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }
    
    - (void)applicationWillEnterForeground:(UIApplication *)application
    {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }
    
    
    
    - (void)applicationWillTerminate:(UIApplication *)application
    {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }
    
    @end
    

    【讨论】:

    • 能否请您再次复制完整代码进行测试
    • 谢谢,您使用的是 AppDelegate.m 还是 .h ?它仍然给我错误,将附上确切的代码给你
    • @heythem500 复制粘贴以上代码到您的应用委托中。首先删除 Appdelegate.m 中的所有旧代码。请欣赏我的回答。
    • 好的,在 - (void)applicationDidBecomeActive:(UIApplication *)application 的最后几行中出现错误“重复声明”
    • 这次我遇到了很多错误,但我回到你之前的编辑并删除了重复的行,它构建得很好你觉得呢?
    猜你喜欢
    • 1970-01-01
    • 2016-02-25
    • 1970-01-01
    • 1970-01-01
    • 2012-09-14
    • 1970-01-01
    • 2022-01-07
    • 2014-08-06
    • 1970-01-01
    相关资源
    最近更新 更多