gpt4 book ai didi

xcode - 存在 Urban Airship 问题的 Phonegap 应用程序

转载 作者:行者123 更新时间:2023-12-01 09:04:50 24 4
gpt4 key购买 nike

我正在尝试将推送通知集成到我的 iOS 应用程序中。这是一个 Phonegap/Cordova 项目。没有 APNS 和 Urban Airship,一切都运行良好。

到目前为止我做了什么?我让它工作,我可以从 UA 向我的手机发送推送消息,但这是使用来自不同论坛的示例代码而不是 UA 文档完成的。所以我开始像 UA 文档中那样做。对此我很困惑并尝试了很多。

所以我做了以下操作:从 UA 获取 Push Sample 并将代码复制到 AppDelegate.m 现在看起来像这样:

 // Create Airship singleton that's used to talk to Urban Airhship servers.
// Please populate AirshipConfig.plist with your info from http://go.urbanairship.com
[UAirship takeOff:takeOffOptions];

[[UAPush shared] resetBadge];//zero badge on startup

[[UAPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound |
UIRemoteNotificationTypeAlert)];

return YES;
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
UALOG(@"Application did become active.");
[[UAPush shared] resetBadge]; //zero badge when resuming from background (iOS 4+)
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
UALOG(@"APN device token: %@", deviceToken);
// Updates the device token and registers the token with UA
[[UAPush shared] registerDeviceToken:deviceToken];


/*
* Some example cases where user notification may be warranted
*
* This code will alert users who try to enable notifications
* from the settings screen, but cannot do so because
* notications are disabled in some capacity through the settings
* app.
*
*/

/*

//Do something when notifications are disabled altogther
if ([application enabledRemoteNotificationTypes] == UIRemoteNotificationTypeNone) {
UALOG(@"iOS Registered a device token, but nothing is enabled!");

//only alert if this is the first registration, or if push has just been
//re-enabled
if ([UAirship shared].deviceToken != nil) { //already been set this session
NSString* okStr = @"OK";
NSString* errorMessage =
@"Unable to turn on notifications. Use the \"Settings\" app to enable notifications.";
NSString *errorTitle = @"Error";
UIAlertView *someError = [[UIAlertView alloc] initWithTitle:errorTitle
message:errorMessage
delegate:nil
cancelButtonTitle:okStr
otherButtonTitles:nil];

[someError show];
[someError release];
}

//Do something when some notification types are disabled
} else if ([application enabledRemoteNotificationTypes] != [UAPush shared].notificationTypes) {

UALOG(@"Failed to register a device token with the requested services. Your notifications may be turned off.");

//only alert if this is the first registration, or if push has just been
//re-enabled
if ([UAirship shared].deviceToken != nil) { //already been set this session

UIRemoteNotificationType disabledTypes = [application enabledRemoteNotificationTypes] ^ [UAPush shared].notificationTypes;



NSString* okStr = @"OK";
NSString* errorMessage = [NSString stringWithFormat:@"Unable to turn on %@. Use the \"Settings\" app to enable these notifications.", [UAPush pushTypeString:disabledTypes]];
NSString *errorTitle = @"Error";
UIAlertView *someError = [[UIAlertView alloc] initWithTitle:errorTitle
message:errorMessage
delegate:nil
cancelButtonTitle:okStr
otherButtonTitles:nil];

[someError show];
[someError release];
}
}

*/
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *) error {
UALOG(@"Failed To Register For Remote Notifications With Error: %@", error);
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UALOG(@"Received remote notification: %@", userInfo);

// Get application state for iOS4.x+ devices, otherwise assume active
UIApplicationState appState = UIApplicationStateActive;
if ([application respondsToSelector:@selector(applicationState)]) {
appState = application.applicationState;
}

[[UAPush shared] handleNotification:userInfo applicationState:appState];
[[UAPush shared] resetBadge]; // zero badge after push received
}

- (void)applicationWillTerminate:(UIApplication *)application {
[UAirship land];
}

它和以前几乎一样,但由 UA 提供。然后我将来自 Push Sample 的其他源文件夹中的文件复制到我的 phonegap 文件夹 Supported Files 中,包括 AirshipConfig.plist。此外,我将 Build Settings 中的 Header Search Paths 设置为 Airship 文件夹,这是我之前复制到 xCode 项目文件夹中的内容。

现在我在 AppDeledate.m 文件中收到错误 (6)“使用未声明的标识符 'UAPush'”。我现在能做什么?

感谢您的帮助...

最佳答案

您需要在 AppDelegate.m 中同时导入 UAirship.h 和 UAPush.h

#import "MainViewController.h"
#import "UAirship.h"
#import "UAPush.h"

这将消除您未声明的标识符问题。愚蠢的 Urban Airship 忘了把这个放在他们的文档中

关于xcode - 存在 Urban Airship 问题的 Phonegap 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9735981/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com