1

我試圖運行GitHub上的Push通知示例。 不幸的是,配置如概述here不起作用。無法運行bms-samples-cordova-hellopush-bms_samples_cordova_push-Swift.h文件未找到

文件說: 在你AppDelegate.m的頂部:

#import "[your-project-name]-Swift.h" 

如果您的項目名稱中有空格或連字符,在導入語句下劃線代替它們。

實施例:

// Project name is "Test Project" or "Test-Project" 
#import "Test_Project-Swift.h" 

所以,我沒有對樣品:

#import "bms_samples_cordova_push-Swift.h" 

ObjC橋接報頭被設置爲:

bms-samples-cordova-push/Plugins/ibm-mfp-core/Bridging-Header.h

RUNPATH設置爲:

@executable_path/Frameworks

但Xcode拋出上面的錯誤。我做錯了什麼?

回答

3

我能得到使用以下步驟運行bms-samples-cordova-hellopush示例應用程序:

  1. 克隆樣本:

    git clone https://github.com/ibm-bluemix-mobile-services/bms-samples-cordova-hellopush

  2. 加了我APPLICATION_ROUTEAPPLICATION_GUID在我的[your-directory]/www/js/index.js(爲我的配置推送通知之後)移動服務上Bluemix入門應用

  3. 添加了iOS平臺,以我的應用程序:

    cordova platform add [email protected]

  4. 新增的科爾多瓦插件:

    cordova plugin add ibm-mfp-push

  5. 睜開[your-app-name].xcodeproj文件在我[your-app-name]/platforms/ios目錄與Xcode(當我被提示:Conver t到最近的快速語法,我點擊取消

  6. 添加橋接頭。去Build settings > Swift Compiler - Code Generation > Objective-C Bridging Header並加入以下路徑:

    [your-project-name]/Plugins/ibm-mfp-core/Bridging-Header.h

bridging header

  • 添加框架參數。去Build Settings > Linking > Runpath Search Paths和增加了以下參數:

    @executable_path/Frameworks

  • executable path

  • 內置項目

  • 未註釋在下列推導入語句我的橋頭。去[your-project-name]/Plugins/ibm-mfp-core/Bridging-Header.h

  • bridging header

  • 已更新爲使用Push SDK
  • 這裏我的客戶端應用程序是我更新AppDelegate.m

    /* 
    Licensed to the Apache Software Foundation (ASF) under one 
    or more contributor license agreements. See the NOTICE file 
    distributed with this work for additional information 
    regarding copyright ownership. The ASF licenses this file 
    to you under the Apache License, Version 2.0 (the 
    "License"); you may not use this file except in compliance 
    with the License. You may obtain a copy of the License at 
    
    http://www.apache.org/licenses/LICENSE-2.0 
    
    Unless required by applicable law or agreed to in writing, 
    software distributed under the License is distributed on an 
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
    KIND, either express or implied. See the License for the 
    specific language governing permissions and limitations 
    under the License. 
    */ 
    
    // 
    // AppDelegate.m 
    // bms-samples-cordova-push 
    // 
    // Created by ___FULLUSERNAME___ on ___DATE___. 
    // Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved. 
    // 
    
    #import "AppDelegate.h" 
    #import "MainViewController.h" 
    #import "bms_samples_cordova_push-Swift.h" 
    
    
    #import <Cordova/CDVPlugin.h> 
    
    @implementation AppDelegate 
    
    @synthesize window, viewController; 
    
    - (id)init 
    { 
        /** If you need to do any extra app-specific initialization, you can do it here 
        * -jm 
        **/ 
        NSHTTPCookieStorage* cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 
    
        [cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; 
    
        int cacheSizeMemory = 8 * 1024 * 1024; // 8MB 
        int cacheSizeDisk = 32 * 1024 * 1024; // 32MB 
    #if __has_feature(objc_arc) 
         NSURLCache* sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"]; 
    #else 
         NSURLCache* sharedCache = [[[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"] autorelease]; 
    #endif 
        [NSURLCache setSharedURLCache:sharedCache]; 
    
        self = [super init]; 
        return self; 
    } 
    
    #pragma mark UIApplicationDelegate implementation 
    
    /** 
    * This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up) 
    */ 
    - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions 
    { 
        CGRect screenBounds = [[UIScreen mainScreen] bounds]; 
    
    #if __has_feature(objc_arc) 
         self.window = [[UIWindow alloc] initWithFrame:screenBounds]; 
    #else 
         self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease]; 
    #endif 
        self.window.autoresizesSubviews = YES; 
    
    #if __has_feature(objc_arc) 
         self.viewController = [[MainViewController alloc] init]; 
    #else 
         self.viewController = [[[MainViewController alloc] init] autorelease]; 
    #endif 
    
        // Set your app's start page by setting the <content src='foo.html' /> tag in config.xml. 
        // If necessary, uncomment the line below to override it. 
        // self.viewController.startPage = @"index.html"; 
    
        // NOTE: To customize the view's frame size (which defaults to full screen), override 
        // [self.viewController viewWillAppear:] in your view controller. 
    
        [[CDVMFPPush sharedInstance] didReceiveRemoteNotificationOnLaunch:launchOptions]; 
    
        self.window.rootViewController = self.viewController; 
        [self.window makeKeyAndVisible]; 
    
        return YES; 
    } 
    
    // this happens while we are running (in the background, or from within our own app) 
    // only valid if bms-samples-cordova-push-Info.plist specifies a protocol to handle 
    - (BOOL)application:(UIApplication*)application openURL:(NSURL*)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation 
    { 
        if (!url) { 
         return NO; 
        } 
    
        // all plugins will get the notification, and their handlers will be called 
        [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]]; 
    
        return YES; 
    } 
    
    // repost all remote and local notification using the default NSNotificationCenter so multiple plugins may respond 
    - (void)   application:(UIApplication*)application 
        didReceiveLocalNotification:(UILocalNotification*)notification 
    { 
        // re-post (broadcast) 
        [[NSNotificationCenter defaultCenter] postNotificationName:CDVLocalNotification object:notification]; 
    } 
    
    
    #if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000 
    - (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window 
    #else 
    - (UIInterfaceOrientationMask)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window 
    #endif 
    { 
        // iPhone doesn't support upside down by default, while the iPad does. Override to allow all orientations always, and let the root view controller decide what's allowed (the supported orientations mask gets intersected). 
        NSUInteger supportedInterfaceOrientations = (1 << UIInterfaceOrientationPortrait) | (1 << UIInterfaceOrientationLandscapeLeft) | (1 << UIInterfaceOrientationLandscapeRight) | (1 << UIInterfaceOrientationPortraitUpsideDown); 
    
        return supportedInterfaceOrientations; 
    } 
    
    - (void)applicationDidReceiveMemoryWarning:(UIApplication*)application 
    { 
        [[NSURLCache sharedURLCache] removeAllCachedResponses]; 
    } 
    
    // Register device token with Bluemix Push Notification Service 
    - (void)application:(UIApplication *)application 
    didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{ 
    
        [[CDVMFPPush sharedInstance] didRegisterForRemoteNotifications:deviceToken]; 
    } 
    
    // Handle error when failed to register device token with APNs 
    - (void)application:(UIApplication*)application 
    didFailToRegisterForRemoteNotificationsWithError:(NSError*)error { 
    
        [[CDVMFPPush sharedInstance] didFailToRegisterForRemoteNotifications:error]; 
    } 
    
    // Handle receiving a remote notification 
    -(void)application:(UIApplication *)application 
    didReceiveRemoteNotification:(NSDictionary *)userInfo 
    fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler { 
    
        [[CDVMFPPush sharedInstance] didReceiveRemoteNotification:userInfo]; 
    } 
    
    @end 
    
    1. Ran t他在iOS設備上品嚐實際註冊和接收推送通知

    希望我沒有錯過任何東西:0)

    我已經聯繫並與科爾多瓦隊開闢了幾個問題,以改善這個樣本的質量使其更容易設置。

    編輯:此外,正如從下面的塞巴斯蒂安指出的,您需要禁用位代碼。

    +2

    如果我完全按照訂單完成這些步驟,它就可以工作。另外,我必須禁用位代碼並創建推送服務的新實例,因爲它引發了HTTP 500錯誤。非常感謝 – Sebastian