Objective c Phonegap 3.0 iOS应用程序在从推送通知打开时冻结
我已经创建了一个带有推送通知的Phonegap 3.0应用程序。我主要关注博客。安卓推送功能运行良好。但我在iOS上接收推送通知时遇到问题。当应用程序在后台运行时,会出现警报,用户点击该警报,应用程序打开并发出ajax请求以检索消息 但是,当应用程序未运行时,无论是在前台还是后台,都会出现警报,当单击时,应用程序打开但立即冻结 我认为有一个类似的问题可以解决我的问题。但是,我的Phonegap 3.0项目中的didFinishLaunchingWithOptions()中的代码与问题中的代码完全不同。我在AppDelegate.m中的代码如下:Objective c Phonegap 3.0 iOS应用程序在从推送通知打开时冻结,objective-c,cordova,push-notification,apple-push-notifications,Objective C,Cordova,Push Notification,Apple Push Notifications,我已经创建了一个带有推送通知的Phonegap 3.0应用程序。我主要关注博客。安卓推送功能运行良好。但我在iOS上接收推送通知时遇到问题。当应用程序在后台运行时,会出现警报,用户点击该警报,应用程序打开并发出ajax请求以检索消息 但是,当应用程序未运行时,无论是在前台还是后台,都会出现警报,当单击时,应用程序打开但立即冻结 我认为有一个类似的问题可以解决我的问题。但是,我的Phonegap 3.0项目中的didFinishLaunchingWithOptions()中的代码与问题中的代码完全
- (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.
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//commented out because it makes the app crash at startup with local notification...
/*NSArray *keyArray = [launchOptions allKeys];
if ([launchOptions objectForKey:[keyArray objectAtIndex:0]]!=nil)
{
NSURL *url = [launchOptions objectForKey:[keyArray objectAtIndex:0]];
self.invokeString = [url absoluteString];
NSLog(@"Mosa_fr_en-busi launchOptions = %@",url);
}*/
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
处理通知的javascript如下所示:
onDeviceReady: function() {
var pushNotification = window.plugins.pushNotification;
if (window.device.platform == 'android' || window.device.platform == 'Android') {
pushNotification.register(app.successHandler, app.errorHandler,{"senderID":"475226855592","ecb":"app.onNotificationGCM"});
}
else{
//so its apple
pushNotification.register(app.tokenHandler,app.errorHandler,{"badge":"true","sound":"true","alert":"true","ecb":"app.onNotificationAPN"});
}
},
以及:
实际上有可能让Phonegap ios推送通知完全工作吗 我解决了这个问题,只需在安装后拔下设备。当仍然连接到xcode时,它导致应用程序在第二次打开时冻结
onNotificationAPN: function(event) {
console.log(event.article_id);
if ( event.article_id )
{
console.log('in event.article_id');
window.location.hash = "article/"+event.article_id;
//localStorage.payload =// event.payload
}
var pushNotification = window.plugins.pushNotification;
if (event.alert) {
console.log('in event.alert');
navigator.notification.alert(event.alert);
}
if (event.badge) {
console.log('in event.badge');
console.log("Set badge on " + pushNotification);
pushNotification.setApplicationIconBadgeNumber(this.successHandler, event.badge);
}
if (event.sound) {
console.log('in event.sound');
var snd = new Media(event.sound);
snd.play();
}
},