我为同样的问题看了很多问题和答案。
而我现在知道的是
我的情况如下:
我想要的是,当我使用Parse的“自定义受众”时,我希望在应用为背景或被杀时获取通知。 但是当我使用Parse的API时,它并不像我想的那样工作。
现在有什么我想念的吗?
我的注册码如下:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler{
NSLog(@"didReceiveRemoteNotification executed : %@",userInfo);
NSInteger bettingIDX = [[userInfo objectForKey:@"betting_idx"] integerValue];
NSString *message = [userInfo objectForKey:@"message"];
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = [NSString stringWithFormat:@"%@",message];
NSUUID *uuid = [NSUUID UUID];
NSString *notificationKey = [uuid UUIDString];
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
NSLog(@"DeviceToken : %@", deviceToken );
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
[Parse setApplicationId:@"applicationID"
clientKey:@"clientID"];
[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
答案 0 :(得分:0)
使用方法didFinishLaunchingWithOptions
:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
if let launchOptions = launchOptions as? [String: AnyObject],
let userInfo = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] as? [String: String] {
}
return true
}
用户点按提醒中的默认按钮或点击(或点击) 应用程序图标如果轻触默认操作按钮(在运行的设备上) iOS),系统启动应用程序,应用程序调用其委托 application:didFinishLaunchingWithOptions:方法,传入 通知有效载荷(用于远程通知)或 本地通知对象(用于本地通知)。虽然 application:didFinishLaunchingWithOptions:不是最好的地方 处理通知,此时获取有效负载给你 在处理程序方法之前启动更新过程的机会 被称为。