iOS 6 and GKAchievement reportAchievementWithCompletionHandler - ios6

I'm making update for iOS game and facing next problem. I use this piece of code
[achievement reportAchievementWithCompletionHandler:^(NSError *error)
{
if (error != nil)
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[storedDictionary setObject:achievement forKey:identifier];
NSLog(#"Game Center: could not report achievement progress for %#, stored in defaults", identifier);
}
}];
to report achievement progress (looks familiar, yeah? Yes, code from Apple tutorial). It works just fine on devices with iOS 5 or less, but nothing happens with iOS 6.
I've found clue, that I don't need to bother with saving postponed achievements in iOS 6, because it will do it for me, but manual is still pretty clear about error handling. What have I missed?

Maybe you mistyped the code for this question? It looks like the line:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
should be:
NSUserDefaults *storedDictionary = [NSUserDefaults standardUserDefaults];

Related

Share Array of UIImages With Text via UIActivityViewController in Swift

I am using UIActivityViewController to share text and images both in Swift using the following code:
#IBAction func shareTapped(_ sender: Any) {
var text = "I am enjoying swift"
var image = UIImage(systemName: "person")
let itemsToShare = [text, image!]
let activityViewController = UIActivityViewController(activityItems: itemsToShare, applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
self.present(activityViewController, animated: true, completion: nil)
}
This works fine when I share it with Skype but when I try to share it with WhatsApp, it only shares text.
There are two questions now:
Can I share both image and text on WhatsApp or iOS does not support this?
Can I share the array of images along with text? If yes, how can I achieve this?
Sorry, currently there is no way to share both image and text together on WhatsApp.
However, you can post one at a time. It is a limitation of WhatsApp under iOS, it is nothing related to UIActivityViewController.
For more read from here

CKModifyBadgeOperation is deprecated in iOS 11. Anyone know an alternative approach?

I have searched, and I cannot find an example. I have also tried adapting this code (recommended elsewhere (CloudKit won't reset my badge count to 0):
func resetBadgeCounter() {
let badgeResetOperation = CKModifyBadgeOperation(badgeValue: 0)
badgeResetOperation.modifyBadgeCompletionBlock = { (error) -> Void in
if error != nil {
print("Error resetting badge: \(String(describing: error))")
}
else {
UIApplication.shared.applicationIconBadgeNumber = 0
}
}
CKContainer.default().add(badgeResetOperation)
}
This works for now, but is no longer supported, and may go away soon.
I thought perhaps I should use a CKModfyRecordsOperation or some other CKDatabaseOperation, but I can't even guess how.
I hope this helps someone as there doesn't seem to be another solution/workaround to this.
Create a Notification Service Extension (UNNotificationServiceExtension) for your app. It is fairly straightforward and is described in detail in Modifying Content in Newly Delivered Notifications. You might already have one, if you do any kind of processing on incoming notifications.
Within the extension, you typically do all the processing of the notification in override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: #escaping (UNNotificationContent) -> Void). The request comes with the content of the notification, which includes the badge number. You can then modify that and pass on to the contentHandler to be displayed. (If you are unsure how to do this, check the link above; it has detailed instructions and code.)
To keep track and reset the badge number when needed, you need to take advantage of an app group (e.g. group.com.tzatziki). This way you can share data between the app and the extension. Creating an app group in Xcode can be done by adding the relevant capability and is explained in App Extension Programming Guide: Handling Common Scenarios.
Use a storage mechanism (within the app group) to keep track of the badge count, e.g. UserDefaults, and use it in the extension to update the badge count. In the aforementioned override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: #escaping (UNNotificationContent) -> Void), you could write something like this:
let badgeNumber = UserDefaults(suiteName: "group.com.tzatziki")?.value(forKey: "badgeNumber") as? NSNumber ?? NSNumber(integerLiteral: 0)
let badgeNumberInt = badgeNumber.intValue + 1
notificationContent.badge = NSNumber(value: badgeNumberInt)
UserDefaults(suiteName: "group.io.prata")?.setValue(notificationContent.badge, forKey: "badgeNumber")
where notificationContent is an instance of UNMutableNotificationContent, originating from request.content.mutableCopy() as? UNMutableNotificationContent
Now, the only thing left to do is to reset the badge count in your app, in the shared UserDefaults and in UIApplication.shared.applicationIconBadgeNumber.
Cheers!
It was reported here: https://levelup.gitconnected.com/how-to-reset-badge-value-of-cloudkit-remote-notification-on-ios-ipados-15-46726a435599 that Apple is aware that they need to maintain CKModifyBadgeOperation until they come up with a replacement API. There is no other solution to this problem because CloudKit resets the badge number whenever it pushes a new notification.
It's probably best to just track the items you are counting and set the app badge count yourself. I reference a local database that has my items in it, and I return the total and set my app badge accordingly.

FBPlacePickerViewController doesn't load any data

I am trying to use FBPlacePickerViewController and it doesn't seem to load any data.
Here is my code:
FBPlacePickerViewController *picker = (FBPlacePickerViewController*)segue.destinationViewController;
picker.navigationController.navigationBarHidden = YES;
picker.delegate = self;
picker.radiusInMeters = 1000;
picker.resultsLimit = 30;
if([TonerAppDelegate instance].lastLocation != nil){
picker.locationCoordinate = [TonerAppDelegate instance].lastLocation.coordinate;
[picker loadData];
}
[TonerAppDelegate instance].lastLocationUpdateFunction = ^{
picker.locationCoordinate = [TonerAppDelegate instance].lastLocation.coordinate;
[picker loadData];
};
It is an embed segue (iOS 6). I verify that the picker is a valid object. The [picker loadData] method does get called, and the coordinate data is perfectly valid. I am not getting any exceptions or warnings. I've allowed my app to access to my location in iOS and I double-verified that in Settings. My iPod is connected to the Internet and the connection works perfectly. All the other apps can use location services without any problem. So, there probably is a problem with my implementation of the place picker. I've also implemented the -(void)placePickerViewControllerDataDidChange:(FBPlacePickerViewController *)placePicker and -(BOOL)placePickerViewController:(FBPlacePickerViewController *)placePicker shouldIncludePlace:(id<FBGraphPlace>) methods of the delegate, and they aren't getting called either. What am I doing wrong?
Thanks,
Can.
Found the answer: I wasn't creating the Facebook session before displaying the place picker. I totally forgot about the session. It'd be nice to see Facebook add an assertion check in loadData method of the picker for an existing Facebook session. I've created the session, and THEN tried my code, and it works perfectly now.

Google maps sdk callout issue ios6

i am using googlemap sdk for ios 6 in my project
The problem i am facing is with Marker options
GMSMarkerOptions *londonOptions = [[GMSMarkerOptions alloc] init];
londonOptions.position = CLLocationCoordinate2DMake(51.500,-0.127);
londonOptions.title = nil;
londonOptions.snippet = nil;
[mapView_ addMarkerWithOptions:londonOptions];
Google states that if i set the title and snippet to nil then the marker would not show a callout if i tap on it.
but it does show an callout on tapping on it.
Has anyone faced this problem
Thanks in advance
Regards
Nitesh
I worked around it by returning an empty uiview :) but as share said, it is fixed now

Why is my MPMediaItem NowPlayingItem returning null?

I am incorporating the iPod player in my app. I am able to create a queue, then play the songs. I am not able to get the current song's property values. I have registered for the notifications and the log shows the notifications are bing triggered.
MPMediaItem *currentItem = self.musicPlayer.nowPlayingItem;
NSLog(#"currentItem = %#", currentItem);
Log output shows: currentItem = (null)
I'm running Xcode 4.5.2 iOS 6.0.
Any help is greatly appreciated.
For anyone else who may run into the same issue, the problem was that I synced my Music after running my application. You need to observe for Library changes:
MPMediaLibraryDidChangeNotification
[[MPMediaLibrary defaultLibrary] beginGeneratingLibraryChangeNotifications];
You wrote NSLog(#"currentItem = %#", currentItem); in your codes but maybe you have not got a full understand of what MPMediaItem is.
MPMediaItem is not NSString, and that's why you got null here. MPMediaItem has a lot of properties including song title, album name and artist name. To access the properties of MPMediaItem such as the title, use valueForProperty: method.
NSLog(#"currentItem = %#", [currentItem valueForProperty:MPMediaItemPropertyTitle])
Something like this.
I also had the problem that I mixed by accident the application player
[MPMusicPlayerController applicationMusicPlayer]
and the ipod player
[MPMusicPlayerController iPodMusicPlayer]
I was using the iPodMusicPlayer for playing music and tried to adjust the volume of the applicationMusicPlayer by accident.
So just beware not to mix them unintentionally ;-)

Resources