Cordova iOS 构建的 Bluemix 推送插件错误
Bluemix Push Plugin error for Cordova iOS build
我正在尝试将 bluemix 推送服务集成到我的 Cordova 应用程序中。使用下面 link 中的示例:
https://github.com/ibm-bluemix-mobile-services/bms-samples-cordova-hellopush
当我遵循 iOS 上的过程并尝试构建应用程序时,它在框架的 IMFClient 上给我以下错误。
已更新:
如果示例中没有正确配置 Bridging-Header.h 文件,您将看到该错误。
请参阅https://github.com/ibm-bluemix-mobile-services/bms-clientsdk-cordova-plugin-push/#configuration
At the top of your AppDelegate.m:
#import "[your-project-name]-Swift.h"
If your project name has spaces or hyphens, replace them with underscores in the import statement.
Add the Bridging Header. Go to Build settings > Swift Compiler - Code
Generation > Objective-C Bridging Header and add the following path:
[your-project-name]/Plugins/ibm-mfp-core/Bridging-Header.h
希望对您有所帮助。
这也可能有帮助:在上一个问题中,我写了设置 Cordova 和 iOS 的步骤。
请记住,您还必须禁用位码。
Unable to run bms-samples-cordova-hellopush - bms_samples_cordova_push-Swift.h file not found
我能够使用以下步骤获得 bms-samples-cordova-hellopush
示例应用程序 运行:
克隆样本:
git clone https://github.com/ibm-bluemix-mobile-services/bms-samples-cordova-hellopush
在我的 [your-directory]/www/js/index.js
中添加了我的 APPLICATION_ROUTE 和 APPLICATION_GUID (在 Bluemix
上为我的 Mobile Services Starter 应用程序配置推送通知后
向我的应用程序添加了 iOS 平台:
cordova platform add ios@3.9
添加了 Cordova 插件:
cordova plugin add ibm-mfp-push
在我的 [your-app-name]/platforms/ios
目录中用 Xcode 打开了我的 [your-app-name].xcodeproj
文件(当我被提示时:转换为最新 Swift语法,我点了取消)
添加了桥接 Header。转到 Build settings > Swift Compiler - Code Generation > Objective-C Bridging Header
并添加以下路径:
[your-project-name]/Plugins/ibm-mfp-core/Bridging-Header.h
添加框架参数。转到 Build Settings > Linking > Runpath Search Paths
并添加以下参数:
@executable_path/Frameworks
已建项目
在我的桥接 header 中取消注释以下 Push 导入语句。去了[your-project-name]/Plugins/ibm-mfp-core/Bridging-Header.h
:
- 更新我的客户端应用程序以使用 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
- 运行 iOS 设备上实际注册和接收推送通知的示例
当应用程序在模拟器上 运行 时,似乎存在架构构建问题。
当应用程序直接 运行 在设备上时,我能够构建并 运行 该应用程序。 :-)
我正在尝试将 bluemix 推送服务集成到我的 Cordova 应用程序中。使用下面 link 中的示例:
https://github.com/ibm-bluemix-mobile-services/bms-samples-cordova-hellopush
当我遵循 iOS 上的过程并尝试构建应用程序时,它在框架的 IMFClient 上给我以下错误。
已更新:
如果示例中没有正确配置 Bridging-Header.h 文件,您将看到该错误。
请参阅https://github.com/ibm-bluemix-mobile-services/bms-clientsdk-cordova-plugin-push/#configuration
At the top of your AppDelegate.m:
#import "[your-project-name]-Swift.h"
If your project name has spaces or hyphens, replace them with underscores in the import statement.
Add the Bridging Header. Go to Build settings > Swift Compiler - Code Generation > Objective-C Bridging Header and add the following path:
[your-project-name]/Plugins/ibm-mfp-core/Bridging-Header.h
希望对您有所帮助。
这也可能有帮助:在上一个问题中,我写了设置 Cordova 和 iOS 的步骤。
请记住,您还必须禁用位码。
Unable to run bms-samples-cordova-hellopush - bms_samples_cordova_push-Swift.h file not found
我能够使用以下步骤获得 bms-samples-cordova-hellopush
示例应用程序 运行:
克隆样本:
git clone https://github.com/ibm-bluemix-mobile-services/bms-samples-cordova-hellopush
在我的
上为我的 Mobile Services Starter 应用程序配置推送通知后[your-directory]/www/js/index.js
中添加了我的 APPLICATION_ROUTE 和 APPLICATION_GUID (在 Bluemix向我的应用程序添加了 iOS 平台:
cordova platform add ios@3.9
添加了 Cordova 插件:
cordova plugin add ibm-mfp-push
在我的
[your-app-name]/platforms/ios
目录中用 Xcode 打开了我的[your-app-name].xcodeproj
文件(当我被提示时:转换为最新 Swift语法,我点了取消)添加了桥接 Header。转到
Build settings > Swift Compiler - Code Generation > Objective-C Bridging Header
并添加以下路径:[your-project-name]/Plugins/ibm-mfp-core/Bridging-Header.h
添加框架参数。转到
Build Settings > Linking > Runpath Search Paths
并添加以下参数:@executable_path/Frameworks
已建项目
在我的桥接 header 中取消注释以下 Push 导入语句。去了
[your-project-name]/Plugins/ibm-mfp-core/Bridging-Header.h
:
- 更新我的客户端应用程序以使用 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
- 运行 iOS 设备上实际注册和接收推送通知的示例
当应用程序在模拟器上 运行 时,似乎存在架构构建问题。
当应用程序直接 运行 在设备上时,我能够构建并 运行 该应用程序。 :-)